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. 6
      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. 98
      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
* @return
* @return status
*/
public boolean typeIsSuccess(){
return this == SUCCESS;
@ -75,7 +75,7 @@ public enum ExecutionStatus {
/**
* status is failure
* @return
* @return status
*/
public boolean typeIsFailure(){
return this == FAILURE || this == NEED_FAULT_TOLERANCE;
@ -83,7 +83,7 @@ public enum ExecutionStatus {
/**
* status is finished
* @return
* @return status
*/
public boolean typeIsFinished(){
@ -93,7 +93,7 @@ public enum ExecutionStatus {
/**
* status is waiting thread
* @return
* @return status
*/
public boolean typeIsWaittingThread(){
return this == WAITTING_THREAD;
@ -101,7 +101,7 @@ public enum ExecutionStatus {
/**
* status is pause
* @return
* @return status
*/
public boolean typeIsPause(){
return this == PAUSE;
@ -109,7 +109,7 @@ public enum ExecutionStatus {
/**
* status is running
* @return
* @return status
*/
public boolean typeIsRunning(){
return this == RUNNING_EXEUTION || this == WAITTING_DEPEND;
@ -117,6 +117,7 @@ public enum ExecutionStatus {
/**
* status is cancel
* @return status
*/
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 ;
* @param taskStateType
* @return
* @param taskStateType task state type
* @return result of execution status
*/
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
*
* @param node node
* @return
* @return true if contains
*/
public boolean containsNode(Node node) {
lock.readLock().lock();
@ -157,7 +157,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
*
* @param fromNode node of origin
* @param toNode node of destination
* @return
* @return true if contains
*/
public boolean containsEdge(Node fromNode, Node toNode) {
lock.readLock().lock();
@ -178,7 +178,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
* get node description
*
* @param node node
* @return
* @return node description
*/
public NodeInfo getNode(Node node) {
lock.readLock().lock();
@ -194,7 +194,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
/**
* Get the number of nodes
*
* @return
* @return the number of nodes
*/
public int getNodesCount() {
lock.readLock().lock();
@ -209,7 +209,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
/**
* Get the number of edges
*
* @return
* @return the number of edges
*/
public int getEdgesCount() {
lock.readLock().lock();
@ -230,7 +230,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
/**
* get the start node of DAG
*
* @return
* @return the start node of DAG
*/
public Collection<Node> getBeginNode() {
lock.readLock().lock();
@ -247,7 +247,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
/**
* get the end node of DAG
*
* @return
* @return the end node of DAG
*/
public Collection<Node> getEndNode() {
@ -266,7 +266,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
* Gets all previous nodes of the node
*
* @param node node id to be calculated
* @return
* @return all previous nodes of the node
*/
public Set<Node> getPreviousNodes(Node node) {
lock.readLock().lock();
@ -283,7 +283,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
* Get all subsequent nodes of the node
*
* @param node node id to be calculated
* @return
* @return all subsequent nodes of the node
*/
public Set<Node> getSubsequentNodes(Node node) {
lock.readLock().lock();
@ -300,7 +300,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
* Gets the degree of entry of the node
*
* @param node node id
* @return
* @return the degree of entry of the node
*/
public int getIndegree(Node node) {
lock.readLock().lock();
@ -331,7 +331,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
/**
* Only DAG has a topological sort
* @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 {
lock.readLock().lock();
@ -385,7 +385,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
* @param fromNode node of origin
* @param toNode node of destination
* @param createNode whether to create a node
* @return
* @return true if added
*/
private boolean isLegalAddEdge(Node fromNode, Node toNode, boolean createNode) {
if (fromNode.equals(toNode)) {
@ -429,7 +429,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
*
* @param node Node id to be calculated
* @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) {
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
* @throws IOException errors
*/
protected void run() throws IOException {
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();
/**
* Parse the execution result
* */
* @param lines lines
* @throws IOException errors
*/
protected abstract void parseExecResult(BufferedReader lines)
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.
* @param cmd shell command to execute.
* @return the output of the executed command.
* @throws IOException errors
*/
public static String execCommand(String... cmd) throws IOException {
return execCommand(null, cmd, 0L);
@ -93,9 +94,9 @@ public class ShellExecutor extends AbstractShell {
* @param env the map of environment key=value
* @param cmd shell command to execute.
* @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,
long timeout) throws IOException {
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 cmd shell command to execute.
* @return the output of the executed command.
* @throws IOException errors
*/
public static String execCommand(Map<String,String> env, String ... cmd)
throws IOException {
@ -119,7 +121,7 @@ public class ShellExecutor extends AbstractShell {
/**
* Execute the shell command
*
* @throws IOException errors
*/
public void execute() throws IOException {
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() {
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 sep The separator to use.
* @param b2 The second byte array.
* @return two byte arrays together using a separator.
*/
public static String toString(final byte [] b1,
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.
* @param buf
* @param buf buffer
* @return byte array
*/
public static byte[] getBytes(ByteBuffer buf) {
@ -506,7 +507,7 @@ public class Bytes {
/**
* Convert a BigDecimal value to a byte array
*
* @param val
* @param val value
* @return the byte array
*/
public static byte[] toBytes(BigDecimal val) {
@ -521,7 +522,7 @@ public class Bytes {
/**
* Converts a byte array to a BigDecimal
*
* @param bytes
* @param bytes bytes array
* @return the char value
*/
public static BigDecimal toBigDecimal(byte[] bytes) {
@ -531,9 +532,9 @@ public class Bytes {
/**
* Converts a byte array to a BigDecimal value
*
* @param bytes
* @param offset
* @param length
* @param bytes bytes array
* @param offset offset
* @param length length
* @return the char value
*/
public static BigDecimal toBigDecimal(byte[] bytes, int offset, final int length) {
@ -652,6 +653,7 @@ public class Bytes {
* @param bytes array to hash
* @param offset offset to start from
* @param length length to hash
* @return hash code
* */
public static int hashCode(byte[] bytes, int offset, int length) {
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
* <i>b</i>. Only the elements of <i>b</i> that satisfy the predicate
* 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}
* 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>
@ -50,6 +50,7 @@ public class CollectionUtils {
*
* @param a the collection to subtract from, must not be null
* @param b the collection to subtract, must not be null
* @param <T> T
* @return a new collection with the results
* @see Collection#removeAll
*/
@ -70,7 +71,7 @@ public class CollectionUtils {
*
* @param str string
* @param separator separator
* @return
* @return string to map
*/
public static Map<String, String> stringToMap(String str, String separator) {
return stringToMap(str, separator, "");
@ -82,7 +83,7 @@ public class CollectionUtils {
* @param str string
* @param separator separator
* @param keyPrefix prefix
* @return
* @return string to map
*/
public static Map<String, String> stringToMap(String str, String separator, String keyPrefix) {
if (null == str || "".equals(str)) {
@ -245,7 +246,7 @@ public class CollectionUtils {
* Only those elements present in the collection will appear as
* 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
* @return the populated cardinality map
*/
@ -265,10 +266,10 @@ public class CollectionUtils {
/**
* Removes certain attributes of each object in the list
* @param originList
* @param exclusionSet
* @param <T>
* @return
* @param originList origin list
* @param exclusionSet exclusion set
* @param <T> T
* @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) {
List<Map<String, Object>> instanceList = new ArrayList<>();

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

@ -29,7 +29,7 @@ import java.io.File;
/**
* common utils
*/
public class CommonUtils {
public class CommonUtils {
private static final Logger logger = LoggerFactory.getLogger(CommonUtils.class);
@ -64,7 +64,7 @@ public class CommonUtils {
/**
* 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(){
String resUploadStartupType = PropertyUtils.getString(Constants.RES_UPLOAD_STARTUP_TYPE);
@ -75,7 +75,7 @@ public class CommonUtils {
/**
* load kerberos configuration
* @throws Exception
* @throws Exception errors
*/
public static void loadKerberosConf()throws Exception{
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
*/
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
* @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
* @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
*/
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
*/
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
*
* @param str
* @return
* @param str date string
* @return yyyy-MM-dd HH:mm:ss format
*/
public static Date stringToDate(String str) {
return parse(str, Constants.YYYY_MM_DD_HH_MM_SS);
@ -127,9 +128,9 @@ public class DateUtils {
/**
* get seconds between two dates
*
* @param d1
* @param d2
* @return
* @param d1 date1
* @param d2 date2
* @return differ seconds
*/
public static long differSec(Date d1, Date d2) {
if(d1 == null || d2 == null){
@ -141,9 +142,9 @@ public class DateUtils {
/**
* get ms between two dates
*
* @param d1
* @param d2
* @return
* @param d1 date1
* @param d2 date2
* @return differ ms
*/
public static long differMs(Date d1, Date d2) {
return Math.abs(d1.getTime() - d2.getTime());
@ -153,9 +154,9 @@ public class DateUtils {
/**
* get hours between two dates
*
* @param d1
* @param d2
* @return
* @param d1 date1
* @param d2 date2
* @return differ hours
*/
public static long diffHours(Date d1, Date d2) {
return (long) Math.ceil(diffMin(d1, d2) / 60.0);
@ -164,9 +165,9 @@ public class DateUtils {
/**
* get minutes between two dates
*
* @param d1
* @param d2
* @return
* @param d1 date1
* @param d2 date2
* @return differ minutes
*/
public static long diffMin(Date d1, Date d2) {
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
*
* @param date
* @param day
* @return
* @param date date
* @param day day
* @return the date of the specified date in the days before and after
*/
public static Date getSomeDay(Date date, int day) {
Calendar calendar = Calendar.getInstance();
@ -190,9 +191,9 @@ public class DateUtils {
/**
* compare two dates
*
* @param future
* @param old
* @return
* @param future future date
* @param old old date
* @return true if future time greater than old time
*/
public static boolean compare(Date future, Date old) {
return future.getTime() > old.getTime();
@ -201,8 +202,8 @@ public class DateUtils {
/**
* convert schedule string to date
*
* @param schedule
* @return
* @param schedule schedule
* @return convert schedule string to date
*/
public static Date getScheduleDate(String schedule) {
return stringToDate(schedule);
@ -211,8 +212,8 @@ public class DateUtils {
/**
* format time to readable
*
* @param ms
* @return
* @param ms ms
* @return format time
*/
public static String format2Readable(long ms) {
@ -228,7 +229,9 @@ public class DateUtils {
/**
* get monday
* <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) {
Calendar cal = Calendar.getInstance();
@ -245,6 +248,8 @@ public class DateUtils {
* get sunday
* <p>
* 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) {
Calendar cal = Calendar.getInstance();
@ -258,7 +263,9 @@ public class DateUtils {
/**
* get first day of month
*/
* @param date date
* @return first day of month
* */
public static Date getFirstDayOfMonth(Date date) {
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) {
Calendar cal = Calendar.getInstance();
@ -284,6 +294,8 @@ public class DateUtils {
/**
* get last day of month
* @param date date
* @return get last day of month
*/
public static Date getLastDayOfMonth(Date date) {
Calendar cal = Calendar.getInstance();
@ -300,8 +312,8 @@ public class DateUtils {
/**
* return YYYY-MM-DD 00:00:00
*
* @param inputDay
* @return
* @param inputDay date
* @return start day
*/
public static Date getStartOfDay(Date inputDay) {
Calendar cal = Calendar.getInstance();
@ -315,8 +327,8 @@ public class DateUtils {
/**
* return YYYY-MM-DD 23:59:59
*
* @param inputDay
* @return
* @param inputDay day
* @return end of day
*/
public static Date getEndOfDay(Date inputDay) {
Calendar cal = Calendar.getInstance();
@ -330,8 +342,8 @@ public class DateUtils {
/**
* return YYYY-MM-DD 00:00:00
*
* @param inputDay
* @return
* @param inputDay day
* @return start of hour
*/
public static Date getStartOfHour(Date inputDay) {
Calendar cal = Calendar.getInstance();
@ -344,8 +356,8 @@ public class DateUtils {
/**
* return YYYY-MM-DD 23:59:59
*
* @param inputDay
* @return
* @param inputDay day
* @return end of hour
*/
public static Date getEndOfHour(Date inputDay) {
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.
* @param businessDate
* @param dateValue
* @return
* @param businessDate business date
* @param dateValue date value
* @return date interval list by business date and date value.
*/
public static List<DateInterval> getDateIntervalList(Date businessDate, String dateValue){
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)
*/
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
*
* @param filename
* @param filename file name
* @return file suffix
*/
public static String suffix(String filename) {
@ -55,7 +55,7 @@ public class FileUtils {
/**
* get download file absolute path and name
*
* @param filename
* @param filename file name
* @return download file name
*/
public static String getDownloadFilename(String filename) {
@ -75,10 +75,10 @@ public class FileUtils {
/**
* directory of process execution
* @param projectId
* @param processDefineId
* @param processInstanceId
* @param taskInstanceId
* @param projectId project id
* @param processDefineId process definition id
* @param processInstanceId process instance id
* @param taskInstanceId task instance id
* @return directory of process execution
*/
public static String getProcessExecDir(int projectId, int processDefineId, int processInstanceId, int taskInstanceId) {
@ -89,9 +89,9 @@ public class FileUtils {
/**
* directory of process instances
* @param projectId
* @param processDefineId
* @param processInstanceId
* @param projectId project id
* @param processDefineId process definition id
* @param processInstanceId process instance id
* @return directory of process instances
*/
public static String getProcessExecDir(int projectId, int processDefineId, int processInstanceId) {
@ -108,10 +108,10 @@ public class FileUtils {
/**
* create directory and user
* @param execLocalPath
* @param userName
* @param logger
* @throws IOException
* @param execLocalPath execute local path
* @param userName user name
* @param logger logger
* @throws IOException errors
*/
public static void createWorkDirAndUserIfAbsent(String execLocalPath, String userName, Logger logger) throws IOException{
//if work dir exists, first delete
@ -145,7 +145,7 @@ public class FileUtils {
*
* @param content content
* @param filePath target file path
* @return
* @return true if write success
*/
public static boolean writeContent2File(String content, String filePath) {
boolean flag = true;
@ -344,7 +344,8 @@ public class FileUtils {
/**
* deletes a directory recursively
* @param dir
* @param dir directory
* @throws IOException in case deletion is unsuccessful
*/
public static void deleteDir(String dir) throws IOException {
@ -361,7 +362,7 @@ public class FileUtils {
* (java.io.File methods returns a boolean)</li>
* </ul>
*
* @param filename
* @param filename file name
* @throws IOException in case deletion is unsuccessful
*/
public static void deleteFile(String filename) throws IOException {
@ -370,8 +371,8 @@ public class FileUtils {
/**
* Gets all the parent subdirectories of the parentDir directory
* @param parentDir
* @return
* @param parentDir parent dir
* @return all dirs
*/
public static File[] getAllDir(String parentDir){
if(parentDir == null || "".equals(parentDir)) {
@ -401,9 +402,9 @@ public class FileUtils {
/**
* Get Content
* @param inputStream
* @return
* @throws IOException
* @param inputStream input stream
* @return string of input stream
* @throws IOException errors
*/
public static String readFile2Str(InputStream inputStream) throws IOException{
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
*
* @param applicationId
* @return
* @param applicationId application id
* @return url of application
*/
public String getApplicationUrl(String 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
*
* @param hdfsFilePath hdfs file path
* @return byte[]
* @return byte[] byte array
* @throws IOException errors
*/
public byte[] catFile(String hdfsFilePath) throws IOException {
@ -209,7 +210,8 @@ public class HadoopUtils implements Closeable {
* @param hdfsFilePath hdfs file path
* @param skipLineNums skip line numbers
* @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 {
@ -230,6 +232,8 @@ public class HadoopUtils implements Closeable {
* Existence of the directory hierarchy is not an error.
*
* @param hdfsPath path to create
* @return mkdir result
* @throws IOException errors
*/
public boolean mkdir(String hdfsPath) throws IOException {
return fs.mkdirs(new Path(hdfsPath));
@ -242,7 +246,8 @@ public class HadoopUtils implements Closeable {
* @param dstPath destination hdfs path
* @param deleteSource whether to delete the src
* @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 {
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 deleteSource whether to delete the src
* @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 {
Path srcPath = new Path(srcFile);
@ -273,8 +280,8 @@ public class HadoopUtils implements Closeable {
* @param dstFile destination file
* @param deleteSource delete source
* @param overwrite overwrite
* @return
* @throws IOException
* @return result of copy hdfs file to local
* @throws IOException errors
*/
public boolean copyHdfsToLocal(String srcHdfsFilePath, String dstFile, boolean deleteSource, boolean overwrite) throws IOException {
Path srcPath = new Path(srcHdfsFilePath);
@ -306,7 +313,7 @@ public class HadoopUtils implements Closeable {
* true, the directory is deleted else throws an exception. In
* case of a file the recursive can be set to either true or false.
* @return true if delete is successful else false.
* @throws IOException
* @throws IOException errors
*/
public boolean delete(String hdfsFilePath, boolean recursive) throws IOException {
return fs.delete(new Path(hdfsFilePath), recursive);
@ -316,7 +323,8 @@ public class HadoopUtils implements Closeable {
* check if exists
*
* @param hdfsFilePath source file path
* @return
* @return result of exists or not
* @throws IOException errors
*/
public boolean exists(String hdfsFilePath) throws IOException {
return fs.exists(new Path(hdfsFilePath));
@ -325,8 +333,9 @@ public class HadoopUtils implements Closeable {
/**
* Gets a list of files in the directory
*
* @param filePath
* @return {@link FileStatus}
* @param filePath file path
* @return {@link FileStatus} file status
* @throws Exception errors
*/
public FileStatus[] listFileStatus(String filePath)throws Exception{
Path path = new Path(filePath);
@ -354,10 +363,9 @@ public class HadoopUtils implements Closeable {
/**
* 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
* @throws JSONException
* @throws IOException
* @throws JSONException json exception
*/
public ExecutionStatus getApplicationStatus(String applicationId) throws JSONException {
if (StringUtils.isEmpty(applicationId)) {
@ -418,6 +426,7 @@ public class HadoopUtils implements Closeable {
* hdfs user dir
*
* @param tenantCode tenant code
* @param userId user id
* @return hdfs resource dir
*/
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
*/
public static String getHdfsTenantDir(String tenantCode) {
@ -467,9 +477,9 @@ public class HadoopUtils implements Closeable {
/**
* getAppAddress
*
* @param appAddress
* @param rmHa
* @return
* @param appAddress app address
* @param rmHa resource manager ha
* @return app address
*/
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
* @param url
* @param url url
* @return http response
*/
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>
*
* @param ipStr ip string
* @return ip to long
*/
public static Long ipToLong(String ipStr) {
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
* @param object
* @param object object
* @return object to json string
*/
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 clazz the class of T
* @param <T> T
* @return an object of type T from the string
* classOfT
*/
@ -99,10 +100,10 @@ public class JSONUtils {
/**
* json to list
*
* @param json
* @param clazz c
* @param <T>
* @return
* @param json json string
* @param clazz class
* @param <T> T
* @return list
*/
public static <T> List<T> toList(String json, Class<T> clazz) {
if (StringUtils.isEmpty(json)) {
@ -122,8 +123,8 @@ public class JSONUtils {
/**
* check json object valid
*
* @param json
* @return
* @param json json
* @return true if valid
*/
public static boolean checkJsonVaild(String json) {
@ -147,6 +148,7 @@ public class JSONUtils {
* node or its child nodes, and returning value it has.
* 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
*
* @return Value of first matching node found, if any; null if none
@ -167,8 +169,8 @@ public class JSONUtils {
*
* {@link #toMap(String, Class, Class)}
*
* @param json
* @return
* @param json json
* @return json to map
*/
public static Map<String, String> toMap(String json) {
if (StringUtils.isEmpty(json)) {
@ -188,16 +190,12 @@ public class JSONUtils {
*
* json to map
*
* <pre>
* String jsonStr = "{\"id\":\"1001\",\"name\":\"Jobs\"}";
* Map<String,String> models = JSONUtils.toMap(jsonStr, String.class,String.class);
* </pre>
* @param json
* @param classK
* @param classV
* @param <K>
* @param <V>
* @return
* @param json json
* @param classK classK
* @param classV classV
* @param <K> K
* @param <V> V
* @return to map
*/
public static <K, V> Map<K, V> toMap(String json, Class<K> classK, Class<V> classV) {
if (StringUtils.isEmpty(json)) {
@ -215,6 +213,7 @@ public class JSONUtils {
/**
* object to json string
* @param object object
* @return json string
*/
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
*
* @return
* @return load average
*/
public static double loadAverage() {
double loadAverage = hal.getProcessor().getSystemLoadAverage();
@ -120,7 +120,7 @@ public class OSUtils {
/**
* get cpu usage
*
* @return
* @return cpu usage
*/
public static double cpuUsage() {
CentralProcessor processor = hal.getProcessor();
@ -136,7 +136,7 @@ public class OSUtils {
/**
* get user list
*
* @return
* @return user list
*/
public static List<String> getUserList() {
List<String> userList = new ArrayList<>();
@ -169,8 +169,8 @@ public class OSUtils {
/**
* get system group information
* @return
* @throws IOException
* @return system group info
* @throws IOException errors
*/
public static String getGroup() throws IOException {
String result = exeCmd("groups");
@ -186,9 +186,9 @@ public class OSUtils {
/**
* Execute the corresponding command of Linux or Windows
*
* @param command
* @return
* @throws IOException
* @param command command
* @return result of execute command
* @throws IOException errors
*/
public static String exeCmd(String command) throws IOException {
BufferedReader br = null;
@ -217,9 +217,9 @@ public class OSUtils {
/**
* Execute the shell
* @param command
* @return
* @throws IOException
* @param command command
* @return result of execute the shell
* @throws IOException errors
*/
public static String exeShell(String command) throws IOException {
return ShellExecutor.execCommand(command);
@ -227,7 +227,7 @@ public class OSUtils {
/**
* get process id
* @return
* @return process id
*/
public static int getProcessID() {
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
@ -236,7 +236,7 @@ public class OSUtils {
/**
* get local host
* @return
* @return host
*/
public static String getHost(){
try {
@ -250,6 +250,7 @@ public class OSUtils {
/**
* whether is macOS
* @return true if mac
*/
public static boolean isMacOS() {
String os = System.getProperty("os.name");
@ -259,6 +260,7 @@ public class OSUtils {
/**
* whether is windows
* @return true if windows
*/
public static boolean isWindows() {
String os = System.getProperty("os.name");
@ -268,8 +270,9 @@ public class OSUtils {
/**
* check memory and cpu usage
* @param conf
* @return
* @param conf conf
* @param isMaster is master
* @return check memory and cpu usage
*/
public static Boolean checkResource(Configuration conf, Boolean isMaster){
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
*
* @param parameterString
* @param parameterMap
* @return
* @param parameterString parameter
* @param parameterMap parameter map
* @return convert parameters place holders
*/
public static String convertParameterPlaceholders(String parameterString, Map<String, String> parameterMap) {
if (StringUtils.isEmpty(parameterString)) {
@ -80,11 +80,11 @@ public class ParameterUtils {
/**
* set in parameter
* @param index
* @param stmt
* @param dataType
* @param value
* @throws Exception
* @param index index
* @param stmt preparedstatement
* @param dataType data type
* @param value value
* @throws Exception errors
*/
public static void setInParameter(int index, PreparedStatement stmt, DataType dataType, String value)throws Exception{
if (dataType.equals(DataType.VARCHAR)){
@ -111,7 +111,11 @@ public class ParameterUtils {
/**
* 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,
CommandType commandType, Date scheduleTime){
@ -120,7 +124,7 @@ public class ParameterUtils {
globalMap.putAll(globalParamMap);
}
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
.getBusinessTime(commandType, scheduleTime);
@ -163,8 +167,8 @@ public class ParameterUtils {
/**
* handle escapes
* @param inputString
* @return
* @param inputString input string
* @return string filter escapes
*/
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(){
String resUploadStartupType = PropertyUtils.getString(Constants.RES_UPLOAD_STARTUP_TYPE);
@ -84,7 +84,7 @@ public class PropertyUtils {
* get property value
*
* @param key property name
* @return
* @return property value
*/
public static String getString(String key) {
return properties.getProperty(key.trim());
@ -102,9 +102,9 @@ public class PropertyUtils {
/**
*
* @param key
* @param defaultValue
* @return
* @param key key
* @param defaultValue default value
* @return property value
*/
public static int getInt(String key, int defaultValue) {
String value = getString(key);
@ -124,7 +124,7 @@ public class PropertyUtils {
* get property value
*
* @param key property name
* @return
* @return property value
*/
public static Boolean getBoolean(String key) {
String value = properties.getProperty(key.trim());
@ -137,9 +137,9 @@ public class PropertyUtils {
/**
* get property long value
* @param key
* @param defaultVal
* @return
* @param key key
* @param defaultVal default value
* @return property value
*/
public static long getLong(String key, long defaultVal) {
String val = getString(key);
@ -148,8 +148,8 @@ public class PropertyUtils {
/**
*
* @param key
* @return
* @param key key
* @return property value
*/
public static long getLong(String key) {
return getLong(key,-1);
@ -157,9 +157,9 @@ public class PropertyUtils {
/**
*
* @param key
* @param defaultVal
* @return
* @param key key
* @param defaultVal default value
* @return property value
*/
public double getDouble(String key, double defaultVal) {
String val = getString(key);
@ -171,7 +171,7 @@ public class PropertyUtils {
* get array
* @param key property name
* @param splitStr separator
* @return
* @return property value through array
*/
public static String[] getArray(String key, String splitStr) {
String value = getString(key);
@ -189,10 +189,10 @@ public class PropertyUtils {
/**
*
* @param key
* @param type
* @param defaultValue
* @param <T>
* @param key key
* @param type type
* @param defaultValue default value
* @param <T> T
* @return get enum value
*/
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.
* @param prefix prefix to search
* @return
* @return all properties with specified prefix
*/
public static Map<String, String> getPrefixedProperties(String prefix) {
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
* @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){
ResInfo resInfo = new ResInfo(cpuUsage,memoryUsage,loadAverage);
@ -89,8 +92,8 @@ public class ResInfo {
/**
* get heart beat info
* @param now
* @return
* @param now now
* @return heart beat info
*/
public static String getHeartBeatInfo(Date now){
return buildHeartbeatForZKInfo(OSUtils.getHost(),
@ -105,14 +108,14 @@ public class ResInfo {
/**
* build heartbeat info for zk
* @param host
* @param port
* @param cpuUsage
* @param memoryUsage
* @param loadAverage
* @param createTime
* @param lastHeartbeatTime
* @return
* @param host host
* @param port port
* @param cpuUsage cpu usage
* @param memoryUsage memory usage
* @param loadAverage load average
* @param createTime create time
* @param lastHeartbeatTime last heartbeat time
* @return heartbeat info
*/
public static String buildHeartbeatForZKInfo(String host , int port ,
double cpuUsage , double memoryUsage,double loadAverage,
@ -128,8 +131,8 @@ public class ResInfo {
/**
* parse heartbeat info for zk
* @param heartBeatInfo
* @return
* @param heartBeatInfo heartbeat info
* @return heartbeat info to Server
*/
public static Server parseHeartbeatForZKInfo(String heartBeatInfo){
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
* @return
* @return all schema list
*/
@SuppressWarnings("unchecked")
public static List<String> getAllSchemaList() {
@ -86,9 +86,9 @@ public class SchemaUtils {
/**
* Determine whether schemaVersion is higher than version
* @param schemaVersion
* @param version
* @return
* @param schemaVersion schema version
* @param version version
* @return Determine whether schemaVersion is higher than version
*/
public static boolean isAGreatVersion(String schemaVersion, String version) {
if(StringUtils.isEmpty(schemaVersion) || StringUtils.isEmpty(version)) {
@ -112,7 +112,7 @@ public class SchemaUtils {
/**
* Gets the current software version number of the system
* @return
* @return current software version
*/
public static String getSoftVersion() {
String soft_version;
@ -131,8 +131,8 @@ public class SchemaUtils {
/**
* Strips the string of space carriage returns and tabs
* @param str
* @return
* @param str string
* @return string removed blank
*/
public static String replaceBlank(String str) {
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 boolean fullLineDelimiter = false;
/**
* Default constructor
*/
public ScriptRunner(Connection connection, boolean autoCommit, boolean stopOnError) {
this.connection = connection;
this.autoCommit = autoCommit;
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) {
this.delimiter = delimiter;
@ -87,6 +80,8 @@ public class ScriptRunner {
*
* @param reader
* - the source of the script
* @throws IOException errors
* @throws SQLException errors
*/
public void runScript(Reader reader) throws IOException, SQLException {
try {

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

@ -42,8 +42,8 @@ public class TaskParametersUtils {
/**
* get task parameters
* @param taskType
* @param parameter
* @param taskType task type
* @param parameter parameter
* @return task parameters
*/
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 runTime run time or schedule time
* @return business time
*/
public static Map<String, String> getBusinessTime(CommandType commandType, Date 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.
* @param ignoreUnresolvablePlaceholders indicates whether unresolvable placeholders should
* be ignored ({@code true}) or cause an exception ({@code false})
* @return PropertyPlaceholderHelper
*/
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 index the index in the original string to start matching against
* @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) {
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 date custom date
* @param ignoreUnresolvablePlaceholders
* @param ignoreUnresolvablePlaceholders ignore unresolvable placeholders
* @return the supplied value with placeholders replaced inline
*/
public static String replacePlaceholders(String value, Date date, boolean ignoreUnresolvablePlaceholders) {
@ -72,8 +72,8 @@ public class TimePlaceholderUtils {
/**
* calculate expression's value
*
* @param expression
* @return
* @param expression expression
* @return expression's value
*/
public static Integer calculate(String expression) {
expression = StringUtils.trim(expression);
@ -320,8 +320,9 @@ public class TimePlaceholderUtils {
/**
* calculate time expresstion
*
* @return <date, date format>
* @param expression expresstion
* @param date date
* @return map with date, date format
*/
public static Map.Entry<Date, String> calcTimeExpression(String expression, Date date) {
Map.Entry<Date, String> resultEntry;
@ -345,8 +346,9 @@ public class TimePlaceholderUtils {
/**
* get first day of month
*
* @return
* @param expression expresstion
* @param date date
* @return first day of month
*/
public static Map.Entry<Date, String> calcMonthBegin(String expression, Date date) {
String addMonthExpr = expression.substring(Constants.MONTH_BEGIN.length() + 1, expression.length() - 1);
@ -367,7 +369,9 @@ public class TimePlaceholderUtils {
/**
* 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) {
String addMonthExpr = expression.substring(Constants.MONTH_END.length() + 1, expression.length() - 1);
@ -388,7 +392,8 @@ public class TimePlaceholderUtils {
/**
* get first day of week
*
* @param expression expresstion
* @param date date
* @return monday
*/
public static Map.Entry<Date, String> calcWeekStart(String expression, Date date) {
@ -409,7 +414,9 @@ public class TimePlaceholderUtils {
/**
* 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) {
String addMonthExpr = expression.substring(Constants.WEEK_END.length() + 1, expression.length() - 1);
@ -430,8 +437,9 @@ public class TimePlaceholderUtils {
/**
* calc months expression
*
* @return <date, format>
* @param expression expresstion
* @param date date
* @return calc months
*/
public static Map.Entry<Date, String> calcMonths(String expression, Date date) {
String addMonthExpr = expression.substring(Constants.ADD_MONTHS.length() + 1, expression.length() - 1);
@ -452,8 +460,9 @@ public class TimePlaceholderUtils {
/**
* calculate time expression
*
*
* @return <date, format>
* @param expression expresstion
* @param date date
* @return calculate time expression with date,format
*/
public static Map.Entry<Date, String> calcMinutes(String expression, Date date) {
if (expression.contains("+")) {
@ -490,8 +499,8 @@ public class TimePlaceholderUtils {
/**
* calculate need minutes
*
* @param minuteExpression
* @return
* @param minuteExpression minute expression
* @return calculate need minutes
*/
public static Integer calcMinutes(String minuteExpression) {
int index = minuteExpression.indexOf("/");

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

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

Loading…
Cancel
Save