Browse Source

Fix some code specification issues (#2482)

* Fix some code specification issues

* Pre-compile regular expressions to improve efficiency and solve concurrency problems

* Solve the nullpoint problem that Object.equals may bring

* Modify if else structure, add {} to improve code readability

Co-Authored-By: daili <daili@users.noreply.github.com>

* Update ResourceTreeVisitor.java

re-run test process

Co-authored-by: daili <daili@users.noreply.github.com>
Co-authored-by: dailidong <dailidong66@gmail.com>
pull/2/head
s751167520 5 years ago committed by GitHub
parent
commit
cb5285384e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/resources/visitor/ResourceTreeVisitor.java
  2. 6
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java
  3. 4
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/datax/DataxParameters.java
  4. 11
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
  5. 86
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessBuilderForWin32.java
  6. 38
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessEnvironmentForWin32.java
  7. 89
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessImplForWin32.java
  8. 20
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstanceMap.java
  9. 16
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Queue.java
  10. 20
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Session.java
  11. 8
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Tenant.java
  12. 8
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/MysqlPerformance.java
  13. 12
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ProcessUtils.java
  14. 2
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/zk/AbstractZKClient.java

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/resources/visitor/ResourceTreeVisitor.java

@ -50,6 +50,7 @@ public class ResourceTreeVisitor implements Visitor{
* visit * visit
* @return resoruce component * @return resoruce component
*/ */
@Override
public ResourceComponent visit() { public ResourceComponent visit() {
ResourceComponent rootDirectory = new Directory(); ResourceComponent rootDirectory = new Directory();
for (Resource resource : resourceList) { for (Resource resource : resourceList) {
@ -117,6 +118,7 @@ public class ResourceTreeVisitor implements Visitor{
}else{ }else{
tempResourceComponent = new FileLeaf(); tempResourceComponent = new FileLeaf();
} }
tempResourceComponent.setName(resource.getAlias()); tempResourceComponent.setName(resource.getAlias());
tempResourceComponent.setFullName(resource.getFullName().replaceFirst("/","")); tempResourceComponent.setFullName(resource.getFullName().replaceFirst("/",""));
tempResourceComponent.setId(resource.getId()); tempResourceComponent.setId(resource.getId());

6
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java

@ -104,7 +104,7 @@ public class ResourcesService extends BaseService {
putMsg(result, Status.HDFS_NOT_STARTUP); putMsg(result, Status.HDFS_NOT_STARTUP);
return result; return result;
} }
String fullName = currentDir.equals("/") ? String.format("%s%s",currentDir,name):String.format("%s/%s",currentDir,name); String fullName = "/".equals(currentDir) ? String.format("%s%s",currentDir,name):String.format("%s/%s",currentDir,name);
if (pid != -1) { if (pid != -1) {
Resource parentResource = resourcesMapper.selectById(pid); Resource parentResource = resourcesMapper.selectById(pid);
@ -229,7 +229,7 @@ public class ResourcesService extends BaseService {
} }
// check resoure name exists // check resoure name exists
String fullName = currentDir.equals("/") ? String.format("%s%s",currentDir,name):String.format("%s/%s",currentDir,name); String fullName = "/".equals(currentDir) ? String.format("%s%s",currentDir,name):String.format("%s/%s",currentDir,name);
if (checkResourceExists(fullName, 0, type.ordinal())) { if (checkResourceExists(fullName, 0, type.ordinal())) {
logger.error("resource {} has exist, can't recreate", name); logger.error("resource {} has exist, can't recreate", name);
putMsg(result, Status.RESOURCE_EXIST); putMsg(result, Status.RESOURCE_EXIST);
@ -839,7 +839,7 @@ public class ResourcesService extends BaseService {
} }
String name = fileName.trim() + "." + nameSuffix; String name = fileName.trim() + "." + nameSuffix;
String fullName = currentDirectory.equals("/") ? String.format("%s%s",currentDirectory,name):String.format("%s/%s",currentDirectory,name); String fullName = "/".equals(currentDirectory) ? String.format("%s%s",currentDirectory,name):String.format("%s/%s",currentDirectory,name);
result = verifyResourceName(fullName,type,loginUser); result = verifyResourceName(fullName,type,loginUser);
if (!result.getCode().equals(Status.SUCCESS.getCode())) { if (!result.getCode().equals(Status.SUCCESS.getCode())) {

4
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/datax/DataxParameters.java

@ -187,7 +187,9 @@ public class DataxParameters extends AbstractParameters {
@Override @Override
public boolean checkParameters() { public boolean checkParameters() {
if (customConfig == null) return false; if (customConfig == null) {
return false;
}
if (customConfig == 0) { if (customConfig == 0) {
return dataSource != 0 return dataSource != 0
&& dataTarget != 0 && dataTarget != 0

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

@ -57,6 +57,12 @@ public class OSUtils {
private OSUtils() {} private OSUtils() {}
/**
* Initialization regularization, solve the problem of pre-compilation performance,
* avoid the thread safety problem of multi-thread operation
*/
private static final Pattern PATTERN = Pattern.compile("\\s+");
/** /**
* get memory usage * get memory usage
@ -219,8 +225,7 @@ public class OSUtils {
List<String> users = new ArrayList<>(); List<String> users = new ArrayList<>();
while (startPos <= endPos) { while (startPos <= endPos) {
Pattern pattern = Pattern.compile("\\s+"); users.addAll(Arrays.asList(PATTERN.split(lines[startPos])));
users.addAll(Arrays.asList(pattern.split(lines[startPos])));
startPos++; startPos++;
} }
@ -313,7 +318,7 @@ public class OSUtils {
String currentProcUserName = System.getProperty("user.name"); String currentProcUserName = System.getProperty("user.name");
String result = exeCmd(String.format("net user \"%s\"", currentProcUserName)); String result = exeCmd(String.format("net user \"%s\"", currentProcUserName));
String line = result.split("\n")[22]; String line = result.split("\n")[22];
String group = Pattern.compile("\\s+").split(line)[1]; String group = PATTERN.split(line)[1];
if (group.charAt(0) == '*') { if (group.charAt(0) == '*') {
return group.substring(1); return group.substring(1);
} else { } else {

86
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessBuilderForWin32.java

@ -189,8 +189,9 @@ public class ProcessBuilderForWin32 {
* @throws NullPointerException if the argument is null * @throws NullPointerException if the argument is null
*/ */
public ProcessBuilderForWin32(List<String> command) { public ProcessBuilderForWin32(List<String> command) {
if (command == null) if (command == null) {
throw new NullPointerException(); throw new NullPointerException();
}
this.command = command; this.command = command;
} }
@ -207,8 +208,9 @@ public class ProcessBuilderForWin32 {
*/ */
public ProcessBuilderForWin32(String... command) { public ProcessBuilderForWin32(String... command) {
this.command = new ArrayList<>(command.length); this.command = new ArrayList<>(command.length);
for (String arg : command) for (String arg : command) {
this.command.add(arg); this.command.add(arg);
}
} }
/** /**
@ -238,8 +240,9 @@ public class ProcessBuilderForWin32 {
* @throws NullPointerException if the argument is null * @throws NullPointerException if the argument is null
*/ */
public ProcessBuilderForWin32 command(List<String> command) { public ProcessBuilderForWin32 command(List<String> command) {
if (command == null) if (command == null) {
throw new NullPointerException(); throw new NullPointerException();
}
this.command = command; this.command = command;
return this; return this;
} }
@ -257,8 +260,9 @@ public class ProcessBuilderForWin32 {
*/ */
public ProcessBuilderForWin32 command(String... command) { public ProcessBuilderForWin32 command(String... command) {
this.command = new ArrayList<>(command.length); this.command = new ArrayList<>(command.length);
for (String arg : command) for (String arg : command) {
this.command.add(arg); this.command.add(arg);
}
return this; return this;
} }
@ -344,11 +348,13 @@ public class ProcessBuilderForWin32 {
*/ */
public Map<String,String> environment() { public Map<String,String> environment() {
SecurityManager security = System.getSecurityManager(); SecurityManager security = System.getSecurityManager();
if (security != null) if (security != null) {
security.checkPermission(new RuntimePermission("getenv.*")); security.checkPermission(new RuntimePermission("getenv.*"));
}
if (environment == null) if (environment == null) {
environment = ProcessEnvironmentForWin32.environment(); environment = ProcessEnvironmentForWin32.environment();
}
assert environment != null; assert environment != null;
@ -369,15 +375,17 @@ public class ProcessBuilderForWin32 {
// for compatibility with old broken code. // for compatibility with old broken code.
// Silently discard any trailing junk. // Silently discard any trailing junk.
if (envstring.indexOf((int) '\u0000') != -1) if (envstring.indexOf((int) '\u0000') != -1) {
envstring = envstring.replaceFirst("\u0000.*", ""); envstring = envstring.replaceFirst("\u0000.*", "");
}
int eqlsign = int eqlsign =
envstring.indexOf('=', ProcessEnvironmentForWin32.MIN_NAME_LENGTH); envstring.indexOf('=', ProcessEnvironmentForWin32.MIN_NAME_LENGTH);
// Silently ignore envstrings lacking the required `='. // Silently ignore envstrings lacking the required `='.
if (eqlsign != -1) if (eqlsign != -1) {
environment.put(envstring.substring(0,eqlsign), environment.put(envstring.substring(0,eqlsign),
envstring.substring(eqlsign+1)); envstring.substring(eqlsign+1));
}
} }
} }
return this; return this;
@ -425,6 +433,7 @@ public class ProcessBuilderForWin32 {
static class NullInputStream extends InputStream { static class NullInputStream extends InputStream {
static final ProcessBuilderForWin32.NullInputStream INSTANCE = new ProcessBuilderForWin32.NullInputStream(); static final ProcessBuilderForWin32.NullInputStream INSTANCE = new ProcessBuilderForWin32.NullInputStream();
private NullInputStream() {} private NullInputStream() {}
@Override
public int read() { return -1; } public int read() { return -1; }
@Override @Override
public int available() { return 0; } public int available() { return 0; }
@ -436,6 +445,7 @@ public class ProcessBuilderForWin32 {
static class NullOutputStream extends OutputStream { static class NullOutputStream extends OutputStream {
static final ProcessBuilderForWin32.NullOutputStream INSTANCE = new ProcessBuilderForWin32.NullOutputStream(); static final ProcessBuilderForWin32.NullOutputStream INSTANCE = new ProcessBuilderForWin32.NullOutputStream();
private NullOutputStream() {} private NullOutputStream() {}
@Override
public void write(int b) throws IOException { public void write(int b) throws IOException {
throw new IOException("Stream closed"); throw new IOException("Stream closed");
} }
@ -516,7 +526,9 @@ public class ProcessBuilderForWin32 {
* }</pre> * }</pre>
*/ */
public static final ProcessBuilderForWin32.Redirect PIPE = new ProcessBuilderForWin32.Redirect() { public static final ProcessBuilderForWin32.Redirect PIPE = new ProcessBuilderForWin32.Redirect() {
@Override
public Type type() { return Type.PIPE; } public Type type() { return Type.PIPE; }
@Override
public String toString() { return type().toString(); }}; public String toString() { return type().toString(); }};
/** /**
@ -531,7 +543,9 @@ public class ProcessBuilderForWin32 {
* }</pre> * }</pre>
*/ */
public static final ProcessBuilderForWin32.Redirect INHERIT = new ProcessBuilderForWin32.Redirect() { public static final ProcessBuilderForWin32.Redirect INHERIT = new ProcessBuilderForWin32.Redirect() {
@Override
public Type type() { return Type.INHERIT; } public Type type() { return Type.INHERIT; }
@Override
public String toString() { return type().toString(); }}; public String toString() { return type().toString(); }};
/** /**
@ -565,12 +579,15 @@ public class ProcessBuilderForWin32 {
* @return a redirect to read from the specified file * @return a redirect to read from the specified file
*/ */
public static ProcessBuilderForWin32.Redirect from(final File file) { public static ProcessBuilderForWin32.Redirect from(final File file) {
if (file == null) if (file == null) {
throw new NullPointerException(); throw new NullPointerException();
}
return new ProcessBuilderForWin32.Redirect() { return new ProcessBuilderForWin32.Redirect() {
@Override
public Type type() { return Type.READ; } public Type type() { return Type.READ; }
@Override @Override
public File file() { return file; } public File file() { return file; }
@Override
public String toString() { public String toString() {
return "redirect to read from file \"" + file + "\""; return "redirect to read from file \"" + file + "\"";
} }
@ -593,12 +610,15 @@ public class ProcessBuilderForWin32 {
* @return a redirect to write to the specified file * @return a redirect to write to the specified file
*/ */
public static ProcessBuilderForWin32.Redirect to(final File file) { public static ProcessBuilderForWin32.Redirect to(final File file) {
if (file == null) if (file == null) {
throw new NullPointerException(); throw new NullPointerException();
}
return new ProcessBuilderForWin32.Redirect() { return new ProcessBuilderForWin32.Redirect() {
@Override
public Type type() { return Type.WRITE; } public Type type() { return Type.WRITE; }
@Override @Override
public File file() { return file; } public File file() { return file; }
@Override
public String toString() { public String toString() {
return "redirect to write to file \"" + file + "\""; return "redirect to write to file \"" + file + "\"";
} }
@ -626,12 +646,15 @@ public class ProcessBuilderForWin32 {
* @return a redirect to append to the specified file * @return a redirect to append to the specified file
*/ */
public static ProcessBuilderForWin32.Redirect appendTo(final File file) { public static ProcessBuilderForWin32.Redirect appendTo(final File file) {
if (file == null) if (file == null) {
throw new NullPointerException(); throw new NullPointerException();
}
return new ProcessBuilderForWin32.Redirect() { return new ProcessBuilderForWin32.Redirect() {
@Override
public Type type() { return Type.APPEND; } public Type type() { return Type.APPEND; }
@Override @Override
public File file() { return file; } public File file() { return file; }
@Override
public String toString() { public String toString() {
return "redirect to append to file \"" + file + "\""; return "redirect to append to file \"" + file + "\"";
} }
@ -647,14 +670,18 @@ public class ProcessBuilderForWin32 {
* instances of the same type associated with non-null equal * instances of the same type associated with non-null equal
* {@code File} instances. * {@code File} instances.
*/ */
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == this) if (obj == this) {
return true; return true;
if (! (obj instanceof ProcessBuilderForWin32.Redirect)) }
if (! (obj instanceof ProcessBuilderForWin32.Redirect)) {
return false; return false;
}
ProcessBuilderForWin32.Redirect r = (ProcessBuilderForWin32.Redirect) obj; ProcessBuilderForWin32.Redirect r = (ProcessBuilderForWin32.Redirect) obj;
if (r.type() != this.type()) if (r.type() != this.type()) {
return false; return false;
}
assert this.file() != null; assert this.file() != null;
return this.file().equals(r.file()); return this.file().equals(r.file());
} }
@ -663,12 +690,14 @@ public class ProcessBuilderForWin32 {
* Returns a hash code value for this {@code Redirect}. * Returns a hash code value for this {@code Redirect}.
* @return a hash code value for this {@code Redirect} * @return a hash code value for this {@code Redirect}
*/ */
@Override
public int hashCode() { public int hashCode() {
File file = file(); File file = file();
if (file == null) if (file == null) {
return super.hashCode(); return super.hashCode();
else } else {
return file.hashCode(); return file.hashCode();
}
} }
/** /**
@ -679,10 +708,11 @@ public class ProcessBuilderForWin32 {
} }
private ProcessBuilderForWin32.Redirect[] redirects() { private ProcessBuilderForWin32.Redirect[] redirects() {
if (redirects == null) if (redirects == null) {
redirects = new ProcessBuilderForWin32.Redirect[] { redirects = new Redirect[] {
ProcessBuilderForWin32.Redirect.PIPE, ProcessBuilderForWin32.Redirect.PIPE, ProcessBuilderForWin32.Redirect.PIPE Redirect.PIPE, Redirect.PIPE, Redirect.PIPE
}; };
}
return redirects; return redirects;
} }
@ -711,9 +741,10 @@ public class ProcessBuilderForWin32 {
*/ */
public ProcessBuilderForWin32 redirectInput(ProcessBuilderForWin32.Redirect source) { public ProcessBuilderForWin32 redirectInput(ProcessBuilderForWin32.Redirect source) {
if (source.type() == ProcessBuilderForWin32.Redirect.Type.WRITE || if (source.type() == ProcessBuilderForWin32.Redirect.Type.WRITE ||
source.type() == ProcessBuilderForWin32.Redirect.Type.APPEND) source.type() == ProcessBuilderForWin32.Redirect.Type.APPEND) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Redirect invalid for reading: " + source); "Redirect invalid for reading: " + source);
}
redirects()[0] = source; redirects()[0] = source;
return this; return this;
} }
@ -741,9 +772,10 @@ public class ProcessBuilderForWin32 {
* @since 1.7 * @since 1.7
*/ */
public ProcessBuilderForWin32 redirectOutput(ProcessBuilderForWin32.Redirect destination) { public ProcessBuilderForWin32 redirectOutput(ProcessBuilderForWin32.Redirect destination) {
if (destination.type() == ProcessBuilderForWin32.Redirect.Type.READ) if (destination.type() == ProcessBuilderForWin32.Redirect.Type.READ) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Redirect invalid for writing: " + destination); "Redirect invalid for writing: " + destination);
}
redirects()[1] = destination; redirects()[1] = destination;
return this; return this;
} }
@ -775,9 +807,10 @@ public class ProcessBuilderForWin32 {
* @since 1.7 * @since 1.7
*/ */
public ProcessBuilderForWin32 redirectError(ProcessBuilderForWin32.Redirect destination) { public ProcessBuilderForWin32 redirectError(ProcessBuilderForWin32.Redirect destination) {
if (destination.type() == ProcessBuilderForWin32.Redirect.Type.READ) if (destination.type() == ProcessBuilderForWin32.Redirect.Type.READ) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Redirect invalid for writing: " + destination); "Redirect invalid for writing: " + destination);
}
redirects()[2] = destination; redirects()[2] = destination;
return this; return this;
} }
@ -1019,15 +1052,18 @@ public class ProcessBuilderForWin32 {
String[] cmdarray = command.toArray(new String[command.size()]); String[] cmdarray = command.toArray(new String[command.size()]);
cmdarray = cmdarray.clone(); cmdarray = cmdarray.clone();
for (String arg : cmdarray) for (String arg : cmdarray) {
if (arg == null) if (arg == null) {
throw new NullPointerException(); throw new NullPointerException();
}
}
// Throws IndexOutOfBoundsException if command is empty // Throws IndexOutOfBoundsException if command is empty
String prog = cmdarray[0]; String prog = cmdarray[0];
SecurityManager security = System.getSecurityManager(); SecurityManager security = System.getSecurityManager();
if (security != null) if (security != null) {
security.checkExec(prog); security.checkExec(prog);
}
String dir = directory == null ? null : directory.toString(); String dir = directory == null ? null : directory.toString();

38
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessEnvironmentForWin32.java

@ -27,22 +27,25 @@ final class ProcessEnvironmentForWin32 extends HashMap<String,String> {
private static String validateName(String name) { private static String validateName(String name) {
// An initial `=' indicates a magic Windows variable name -- OK // An initial `=' indicates a magic Windows variable name -- OK
if (name.indexOf('=', 1) != -1 || if (name.indexOf('=', 1) != -1 ||
name.indexOf('\u0000') != -1) name.indexOf('\u0000') != -1) {
throw new IllegalArgumentException throw new IllegalArgumentException
("Invalid environment variable name: \"" + name + "\""); ("Invalid environment variable name: \"" + name + "\"");
}
return name; return name;
} }
private static String validateValue(String value) { private static String validateValue(String value) {
if (value.indexOf('\u0000') != -1) if (value.indexOf('\u0000') != -1) {
throw new IllegalArgumentException throw new IllegalArgumentException
("Invalid environment variable value: \"" + value + "\""); ("Invalid environment variable value: \"" + value + "\"");
}
return value; return value;
} }
private static String nonNullString(Object o) { private static String nonNullString(Object o) {
if (o == null) if (o == null) {
throw new NullPointerException(); throw new NullPointerException();
}
return (String) o; return (String) o;
} }
@ -70,26 +73,38 @@ final class ProcessEnvironmentForWin32 extends HashMap<String,String> {
private static class CheckedEntry implements Entry<String,String> { private static class CheckedEntry implements Entry<String,String> {
private final Entry<String,String> e; private final Entry<String,String> e;
public CheckedEntry(Entry<String,String> e) {this.e = e;} public CheckedEntry(Entry<String,String> e) {this.e = e;}
@Override
public String getKey() { return e.getKey();} public String getKey() { return e.getKey();}
@Override
public String getValue() { return e.getValue();} public String getValue() { return e.getValue();}
@Override
public String setValue(String value) { public String setValue(String value) {
return e.setValue(validateValue(value)); return e.setValue(validateValue(value));
} }
@Override
public String toString() { return getKey() + "=" + getValue();} public String toString() { return getKey() + "=" + getValue();}
@Override
public boolean equals(Object o) {return e.equals(o);} public boolean equals(Object o) {return e.equals(o);}
@Override
public int hashCode() {return e.hashCode();} public int hashCode() {return e.hashCode();}
} }
private static class CheckedEntrySet extends AbstractSet<Entry<String,String>> { private static class CheckedEntrySet extends AbstractSet<Entry<String,String>> {
private final Set<Entry<String,String>> s; private final Set<Entry<String,String>> s;
public CheckedEntrySet(Set<Entry<String,String>> s) {this.s = s;} public CheckedEntrySet(Set<Entry<String,String>> s) {this.s = s;}
@Override
public int size() {return s.size();} public int size() {return s.size();}
@Override
public boolean isEmpty() {return s.isEmpty();} public boolean isEmpty() {return s.isEmpty();}
@Override
public void clear() { s.clear();} public void clear() { s.clear();}
@Override
public Iterator<Entry<String,String>> iterator() { public Iterator<Entry<String,String>> iterator() {
return new Iterator<Entry<String,String>>() { return new Iterator<Entry<String,String>>() {
Iterator<Entry<String,String>> i = s.iterator(); Iterator<Entry<String,String>> i = s.iterator();
@Override
public boolean hasNext() { return i.hasNext();} public boolean hasNext() { return i.hasNext();}
@Override
public Entry<String,String> next() { public Entry<String,String> next() {
return new CheckedEntry(i.next()); return new CheckedEntry(i.next());
} }
@ -104,18 +119,22 @@ final class ProcessEnvironmentForWin32 extends HashMap<String,String> {
nonNullString(e.getValue()); nonNullString(e.getValue());
return e; return e;
} }
@Override
public boolean contains(Object o) {return s.contains(checkedEntry(o));} public boolean contains(Object o) {return s.contains(checkedEntry(o));}
@Override
public boolean remove(Object o) {return s.remove(checkedEntry(o));} public boolean remove(Object o) {return s.remove(checkedEntry(o));}
} }
private static class CheckedValues extends AbstractCollection<String> { private static class CheckedValues extends AbstractCollection<String> {
private final Collection<String> c; private final Collection<String> c;
public CheckedValues(Collection<String> c) {this.c = c;} public CheckedValues(Collection<String> c) {this.c = c;}
@Override
public int size() {return c.size();} public int size() {return c.size();}
@Override @Override
public boolean isEmpty() {return c.isEmpty();} public boolean isEmpty() {return c.isEmpty();}
@Override @Override
public void clear() { c.clear();} public void clear() { c.clear();}
@Override
public Iterator<String> iterator() {return c.iterator();} public Iterator<String> iterator() {return c.iterator();}
@Override @Override
public boolean contains(Object o) {return c.contains(nonNullString(o));} public boolean contains(Object o) {return c.contains(nonNullString(o));}
@ -126,11 +145,17 @@ final class ProcessEnvironmentForWin32 extends HashMap<String,String> {
private static class CheckedKeySet extends AbstractSet<String> { private static class CheckedKeySet extends AbstractSet<String> {
private final Set<String> s; private final Set<String> s;
public CheckedKeySet(Set<String> s) {this.s = s;} public CheckedKeySet(Set<String> s) {this.s = s;}
@Override
public int size() {return s.size();} public int size() {return s.size();}
@Override
public boolean isEmpty() {return s.isEmpty();} public boolean isEmpty() {return s.isEmpty();}
@Override
public void clear() { s.clear();} public void clear() { s.clear();}
@Override
public Iterator<String> iterator() {return s.iterator();} public Iterator<String> iterator() {return s.iterator();}
@Override
public boolean contains(Object o) {return s.contains(nonNullString(o));} public boolean contains(Object o) {return s.contains(nonNullString(o));}
@Override
public boolean remove(Object o) {return s.remove(nonNullString(o));} public boolean remove(Object o) {return s.remove(nonNullString(o));}
} }
@Override @Override
@ -147,6 +172,7 @@ final class ProcessEnvironmentForWin32 extends HashMap<String,String> {
} }
private static final class NameComparator implements Comparator<String> { private static final class NameComparator implements Comparator<String> {
@Override
public int compare(String s1, String s2) { public int compare(String s1, String s2) {
// We can't use String.compareToIgnoreCase since it // We can't use String.compareToIgnoreCase since it
// canonicalizes to lower case, while Windows // canonicalizes to lower case, while Windows
@ -163,7 +189,9 @@ final class ProcessEnvironmentForWin32 extends HashMap<String,String> {
c2 = Character.toUpperCase(c2); c2 = Character.toUpperCase(c2);
if (c1 != c2) if (c1 != c2)
// No overflow because of numeric promotion // No overflow because of numeric promotion
{
return c1 - c2; return c1 - c2;
}
} }
} }
return n1 - n2; return n1 - n2;
@ -171,6 +199,7 @@ final class ProcessEnvironmentForWin32 extends HashMap<String,String> {
} }
private static final class EntryComparator implements Comparator<Entry<String,String>> { private static final class EntryComparator implements Comparator<Entry<String,String>> {
@Override
public int compare(Entry<String,String> e1, public int compare(Entry<String,String> e1,
Entry<String,String> e2) { Entry<String,String> e2) {
return nameComparator.compare(e1.getKey(), e2.getKey()); return nameComparator.compare(e1.getKey(), e2.getKey());
@ -278,8 +307,9 @@ final class ProcessEnvironmentForWin32 extends HashMap<String,String> {
// add the environment variable to the child, if it exists in parent // add the environment variable to the child, if it exists in parent
private static void addToEnvIfSet(StringBuilder sb, String name) { private static void addToEnvIfSet(StringBuilder sb, String name) {
String s = getenv(name); String s = getenv(name);
if (s != null) if (s != null) {
addToEnv(sb, name, s); addToEnv(sb, name, s);
}
} }
private static void addToEnv(StringBuilder sb, String name, String val) { private static void addToEnv(StringBuilder sb, String name, String val) {

89
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessImplForWin32.java

@ -93,13 +93,15 @@ public class ProcessImplForWin32 extends Process {
if (append) { if (append) {
String path = f.getPath(); String path = f.getPath();
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) if (sm != null) {
sm.checkWrite(path); sm.checkWrite(path);
}
long handle = openForAtomicAppend(path); long handle = openForAtomicAppend(path);
final FileDescriptor fd = new FileDescriptor(); final FileDescriptor fd = new FileDescriptor();
setHandle(fd, handle); setHandle(fd, handle);
return AccessController.doPrivileged( return AccessController.doPrivileged(
new PrivilegedAction<FileOutputStream>() { new PrivilegedAction<FileOutputStream>() {
@Override
public FileOutputStream run() { public FileOutputStream run() {
return new FileOutputStream(fd); return new FileOutputStream(fd);
} }
@ -133,30 +135,30 @@ public class ProcessImplForWin32 extends Process {
} else { } else {
stdHandles = new long[3]; stdHandles = new long[3];
if (redirects[0] == ProcessBuilderForWin32.Redirect.PIPE) if (redirects[0] == ProcessBuilderForWin32.Redirect.PIPE) {
stdHandles[0] = -1L; stdHandles[0] = -1L;
else if (redirects[0] == ProcessBuilderForWin32.Redirect.INHERIT) } else if (redirects[0] == ProcessBuilderForWin32.Redirect.INHERIT) {
stdHandles[0] = getHandle(FileDescriptor.in); stdHandles[0] = getHandle(FileDescriptor.in);
else { } else {
f0 = new FileInputStream(redirects[0].file()); f0 = new FileInputStream(redirects[0].file());
stdHandles[0] = getHandle(f0.getFD()); stdHandles[0] = getHandle(f0.getFD());
} }
if (redirects[1] == ProcessBuilderForWin32.Redirect.PIPE) if (redirects[1] == ProcessBuilderForWin32.Redirect.PIPE) {
stdHandles[1] = -1L; stdHandles[1] = -1L;
else if (redirects[1] == ProcessBuilderForWin32.Redirect.INHERIT) } else if (redirects[1] == ProcessBuilderForWin32.Redirect.INHERIT) {
stdHandles[1] = getHandle(FileDescriptor.out); stdHandles[1] = getHandle(FileDescriptor.out);
else { } else {
f1 = newFileOutputStream(redirects[1].file(), f1 = newFileOutputStream(redirects[1].file(),
redirects[1].append()); redirects[1].append());
stdHandles[1] = getHandle(f1.getFD()); stdHandles[1] = getHandle(f1.getFD());
} }
if (redirects[2] == ProcessBuilderForWin32.Redirect.PIPE) if (redirects[2] == ProcessBuilderForWin32.Redirect.PIPE) {
stdHandles[2] = -1L; stdHandles[2] = -1L;
else if (redirects[2] == ProcessBuilderForWin32.Redirect.INHERIT) } else if (redirects[2] == ProcessBuilderForWin32.Redirect.INHERIT) {
stdHandles[2] = getHandle(FileDescriptor.err); stdHandles[2] = getHandle(FileDescriptor.err);
else { } else {
f2 = newFileOutputStream(redirects[2].file(), f2 = newFileOutputStream(redirects[2].file(),
redirects[2].append()); redirects[2].append());
stdHandles[2] = getHandle(f2.getFD()); stdHandles[2] = getHandle(f2.getFD());
@ -167,10 +169,19 @@ public class ProcessImplForWin32 extends Process {
} finally { } finally {
// In theory, close() can throw IOException // In theory, close() can throw IOException
// (although it is rather unlikely to happen here) // (although it is rather unlikely to happen here)
try { if (f0 != null) f0.close(); } try { if (f0 != null) {
f0.close();
}
}
finally { finally {
try { if (f1 != null) f1.close(); } try { if (f1 != null) {
finally { if (f2 != null) f2.close(); } f1.close();
}
}
finally { if (f2 != null) {
f2.close();
}
}
} }
} }
@ -193,8 +204,9 @@ public class ProcessImplForWin32 extends Process {
private static String[] getTokensFromCommand(String command) { private static String[] getTokensFromCommand(String command) {
ArrayList<String> matchList = new ArrayList<>(8); ArrayList<String> matchList = new ArrayList<>(8);
Matcher regexMatcher = ProcessImplForWin32.LazyPattern.PATTERN.matcher(command); Matcher regexMatcher = ProcessImplForWin32.LazyPattern.PATTERN.matcher(command);
while (regexMatcher.find()) while (regexMatcher.find()) {
matchList.add(regexMatcher.group()); matchList.add(regexMatcher.group());
}
return matchList.toArray(new String[matchList.size()]); return matchList.toArray(new String[matchList.size()]);
} }
@ -378,8 +390,9 @@ public class ProcessImplForWin32 extends Process {
// .bat files don't include backslashes as part of the quote // .bat files don't include backslashes as part of the quote
private static int countLeadingBackslash(int verificationType, private static int countLeadingBackslash(int verificationType,
CharSequence input, int start) { CharSequence input, int start) {
if (verificationType == VERIFICATION_CMD_BAT) if (verificationType == VERIFICATION_CMD_BAT) {
return 0; return 0;
}
int j; int j;
for (j = start - 1; j >= 0 && input.charAt(j) == BACKSLASH; j--) { for (j = start - 1; j >= 0 && input.charAt(j) == BACKSLASH; j--) {
// just scanning backwards // just scanning backwards
@ -417,8 +430,9 @@ public class ProcessImplForWin32 extends Process {
String executablePath = new File(cmd[0]).getPath(); String executablePath = new File(cmd[0]).getPath();
// No worry about internal, unpaired ["], and redirection/piping. // No worry about internal, unpaired ["], and redirection/piping.
if (needsEscaping(VERIFICATION_LEGACY, executablePath) ) if (needsEscaping(VERIFICATION_LEGACY, executablePath) ) {
executablePath = quoteString(executablePath); executablePath = quoteString(executablePath);
}
cmdstr = createCommandLine( cmdstr = createCommandLine(
//legacy mode doesn't worry about extended verification //legacy mode doesn't worry about extended verification
@ -442,16 +456,18 @@ public class ProcessImplForWin32 extends Process {
// Restore original command line. // Restore original command line.
StringBuilder join = new StringBuilder(); StringBuilder join = new StringBuilder();
// terminal space in command line is ok // terminal space in command line is ok
for (String s : cmd) for (String s : cmd) {
join.append(s).append(' '); join.append(s).append(' ');
}
// Parse the command line again. // Parse the command line again.
cmd = getTokensFromCommand(join.toString()); cmd = getTokensFromCommand(join.toString());
executablePath = getExecutablePath(cmd[0]); executablePath = getExecutablePath(cmd[0]);
// Check new executable name once more // Check new executable name once more
if (security != null) if (security != null) {
security.checkExec(executablePath); security.checkExec(executablePath);
}
} }
// Quotation protects from interpretation of the [path] argument as // Quotation protects from interpretation of the [path] argument as
@ -471,28 +487,29 @@ public class ProcessImplForWin32 extends Process {
AccessController.doPrivileged( AccessController.doPrivileged(
new PrivilegedAction<Void>() { new PrivilegedAction<Void>() {
@Override
public Void run() { public Void run() {
if (stdHandles[0] == -1L) if (stdHandles[0] == -1L) {
stdinStream = ProcessBuilderForWin32.NullOutputStream.INSTANCE; stdinStream = ProcessBuilderForWin32.NullOutputStream.INSTANCE;
else { } else {
FileDescriptor stdinFd = new FileDescriptor(); FileDescriptor stdinFd = new FileDescriptor();
setHandle(stdinFd, stdHandles[0]); setHandle(stdinFd, stdHandles[0]);
stdinStream = new BufferedOutputStream( stdinStream = new BufferedOutputStream(
new FileOutputStream(stdinFd)); new FileOutputStream(stdinFd));
} }
if (stdHandles[1] == -1L) if (stdHandles[1] == -1L) {
stdoutStream = ProcessBuilderForWin32.NullInputStream.INSTANCE; stdoutStream = ProcessBuilderForWin32.NullInputStream.INSTANCE;
else { } else {
FileDescriptor stdoutFd = new FileDescriptor(); FileDescriptor stdoutFd = new FileDescriptor();
setHandle(stdoutFd, stdHandles[1]); setHandle(stdoutFd, stdHandles[1]);
stdoutStream = new BufferedInputStream( stdoutStream = new BufferedInputStream(
new FileInputStream(stdoutFd)); new FileInputStream(stdoutFd));
} }
if (stdHandles[2] == -1L) if (stdHandles[2] == -1L) {
stderrStream = ProcessBuilderForWin32.NullInputStream.INSTANCE; stderrStream = ProcessBuilderForWin32.NullInputStream.INSTANCE;
else { } else {
FileDescriptor stderrFd = new FileDescriptor(); FileDescriptor stderrFd = new FileDescriptor();
setHandle(stderrFd, stdHandles[2]); setHandle(stderrFd, stdHandles[2]);
stderrStream = new FileInputStream(stderrFd); stderrStream = new FileInputStream(stderrFd);
@ -501,33 +518,41 @@ public class ProcessImplForWin32 extends Process {
return null; }}); return null; }});
} }
@Override
public OutputStream getOutputStream() { public OutputStream getOutputStream() {
return stdinStream; return stdinStream;
} }
@Override
public InputStream getInputStream() { public InputStream getInputStream() {
return stdoutStream; return stdoutStream;
} }
@Override
public InputStream getErrorStream() { public InputStream getErrorStream() {
return stderrStream; return stderrStream;
} }
@Override
protected void finalize() { protected void finalize() {
closeHandle(handle); closeHandle(handle);
} }
@Override
public int exitValue() { public int exitValue() {
int exitCode = getExitCodeProcess(handle); int exitCode = getExitCodeProcess(handle);
if (exitCode == STILL_ACTIVE) if (exitCode == STILL_ACTIVE) {
throw new IllegalThreadStateException("process has not exited"); throw new IllegalThreadStateException("process has not exited");
}
return exitCode; return exitCode;
} }
@Override
public int waitFor() throws InterruptedException { public int waitFor() throws InterruptedException {
waitForInterruptibly(handle); waitForInterruptibly(handle);
if (Thread.interrupted()) if (Thread.interrupted()) {
throw new InterruptedException(); throw new InterruptedException();
}
return exitValue(); return exitValue();
} }
@ -535,8 +560,12 @@ public class ProcessImplForWin32 extends Process {
public boolean waitFor(long timeout, TimeUnit unit) public boolean waitFor(long timeout, TimeUnit unit)
throws InterruptedException throws InterruptedException
{ {
if (getExitCodeProcess(handle) != STILL_ACTIVE) return true; if (getExitCodeProcess(handle) != STILL_ACTIVE) {
if (timeout <= 0) return false; return true;
}
if (timeout <= 0) {
return false;
}
long remainingNanos = unit.toNanos(timeout); long remainingNanos = unit.toNanos(timeout);
long deadline = System.nanoTime() + remainingNanos ; long deadline = System.nanoTime() + remainingNanos ;
@ -545,8 +574,9 @@ public class ProcessImplForWin32 extends Process {
// Round up to next millisecond // Round up to next millisecond
long msTimeout = TimeUnit.NANOSECONDS.toMillis(remainingNanos + 999_999L); long msTimeout = TimeUnit.NANOSECONDS.toMillis(remainingNanos + 999_999L);
waitForTimeoutInterruptibly(handle, msTimeout); waitForTimeoutInterruptibly(handle, msTimeout);
if (Thread.interrupted()) if (Thread.interrupted()) {
throw new InterruptedException(); throw new InterruptedException();
}
if (getExitCodeProcess(handle) != STILL_ACTIVE) { if (getExitCodeProcess(handle) != STILL_ACTIVE) {
return true; return true;
} }
@ -556,6 +586,7 @@ public class ProcessImplForWin32 extends Process {
return (getExitCodeProcess(handle) != STILL_ACTIVE); return (getExitCodeProcess(handle) != STILL_ACTIVE);
} }
@Override
public void destroy() { terminateProcess(handle); } public void destroy() { terminateProcess(handle); }
@Override @Override

20
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstanceMap.java

@ -91,14 +91,24 @@ public class ProcessInstanceMap {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || getClass() != o.getClass()) return false; return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ProcessInstanceMap that = (ProcessInstanceMap) o; ProcessInstanceMap that = (ProcessInstanceMap) o;
if (id != that.id) return false; if (id != that.id) {
if (parentProcessInstanceId != that.parentProcessInstanceId) return false; return false;
if (parentTaskInstanceId != that.parentTaskInstanceId) return false; }
if (parentProcessInstanceId != that.parentProcessInstanceId) {
return false;
}
if (parentTaskInstanceId != that.parentTaskInstanceId) {
return false;
}
return processInstanceId == that.processInstanceId; return processInstanceId == that.processInstanceId;
} }

16
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Queue.java

@ -104,13 +104,21 @@ public class Queue {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || getClass() != o.getClass()) return false; return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Queue queue1 = (Queue) o; Queue queue1 = (Queue) o;
if (id != queue1.id) return false; if (id != queue1.id) {
if (!queueName.equals(queue1.queueName)) return false; return false;
}
if (!queueName.equals(queue1.queueName)) {
return false;
}
return queue.equals(queue1.queue); return queue.equals(queue1.queue);
} }

20
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Session.java

@ -93,14 +93,24 @@ public class Session {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || getClass() != o.getClass()) return false; return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Session session = (Session) o; Session session = (Session) o;
if (userId != session.userId) return false; if (userId != session.userId) {
if (!id.equals(session.id)) return false; return false;
if (!lastLoginTime.equals(session.lastLoginTime)) return false; }
if (!id.equals(session.id)) {
return false;
}
if (!lastLoginTime.equals(session.lastLoginTime)) {
return false;
}
return ip.equals(session.ip); return ip.equals(session.ip);
} }

8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Tenant.java

@ -166,8 +166,12 @@ public class Tenant {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || getClass() != o.getClass()) return false; return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Tenant tenant = (Tenant) o; Tenant tenant = (Tenant) o;

8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/MysqlPerformance.java

@ -56,7 +56,7 @@ public class MysqlPerformance extends BaseDBPerformance{
try (ResultSet rs1 = pstmt.executeQuery("show global variables")) { try (ResultSet rs1 = pstmt.executeQuery("show global variables")) {
while(rs1.next()){ while(rs1.next()){
if(rs1.getString(VARIABLE_NAME).equalsIgnoreCase("MAX_CONNECTIONS")){ if("MAX_CONNECTIONS".equalsIgnoreCase(rs1.getString(VARIABLE_NAME))){
monitorRecord.setMaxConnections( Long.parseLong(rs1.getString("value"))); monitorRecord.setMaxConnections( Long.parseLong(rs1.getString("value")));
} }
} }
@ -64,11 +64,11 @@ public class MysqlPerformance extends BaseDBPerformance{
try (ResultSet rs2 = pstmt.executeQuery("show global status")) { try (ResultSet rs2 = pstmt.executeQuery("show global status")) {
while(rs2.next()){ while(rs2.next()){
if(rs2.getString(VARIABLE_NAME).equalsIgnoreCase("MAX_USED_CONNECTIONS")){ if("MAX_USED_CONNECTIONS".equalsIgnoreCase(rs2.getString(VARIABLE_NAME))){
monitorRecord.setMaxUsedConnections(Long.parseLong(rs2.getString("value"))); monitorRecord.setMaxUsedConnections(Long.parseLong(rs2.getString("value")));
}else if(rs2.getString(VARIABLE_NAME).equalsIgnoreCase("THREADS_CONNECTED")){ }else if("THREADS_CONNECTED".equalsIgnoreCase(rs2.getString(VARIABLE_NAME))){
monitorRecord.setThreadsConnections(Long.parseLong(rs2.getString("value"))); monitorRecord.setThreadsConnections(Long.parseLong(rs2.getString("value")));
}else if(rs2.getString(VARIABLE_NAME).equalsIgnoreCase("THREADS_RUNNING")){ }else if("THREADS_RUNNING".equalsIgnoreCase(rs2.getString(VARIABLE_NAME))){
monitorRecord.setThreadsRunningConnections(Long.parseLong(rs2.getString("value"))); monitorRecord.setThreadsRunningConnections(Long.parseLong(rs2.getString("value")));
} }
} }

12
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ProcessUtils.java

@ -46,6 +46,14 @@ public class ProcessUtils {
*/ */
private final static Logger logger = LoggerFactory.getLogger(ProcessUtils.class); private final static Logger logger = LoggerFactory.getLogger(ProcessUtils.class);
/**
* Initialization regularization, solve the problem of pre-compilation performance,
* avoid the thread safety problem of multi-thread operation
*/
private static final Pattern MACPATTERN = Pattern.compile("-[+|-]-\\s(\\d+)");
private static final Pattern WINDOWSATTERN = Pattern.compile("(\\d+)");
/** /**
* build command line characters * build command line characters
* @param commandList command list * @param commandList command list
@ -356,10 +364,10 @@ public class ProcessUtils {
// pstree pid get sub pids // pstree pid get sub pids
if (OSUtils.isMacOS()) { if (OSUtils.isMacOS()) {
String pids = OSUtils.exeCmd("pstree -sp " + processId); String pids = OSUtils.exeCmd("pstree -sp " + processId);
mat = Pattern.compile("-[+|-]-\\s(\\d+)").matcher(pids); mat = MACPATTERN.matcher(pids);
} else { } else {
String pids = OSUtils.exeCmd("pstree -p " + processId); String pids = OSUtils.exeCmd("pstree -p " + processId);
mat = Pattern.compile("(\\d+)").matcher(pids); mat = WINDOWSATTERN.matcher(pids);
} }
while (mat.find()){ while (mat.find()){

2
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/zk/AbstractZKClient.java

@ -272,7 +272,7 @@ public abstract class AbstractZKClient extends ZookeeperCachedOperator {
try { try {
mutex.release(); mutex.release();
} catch (Exception e) { } catch (Exception e) {
if(e.getMessage().equals("instance must be started before calling this method")){ if("instance must be started before calling this method".equals(e.getMessage())){
logger.warn("lock release"); logger.warn("lock release");
}else{ }else{
logger.error("lock release failed",e); logger.error("lock release failed",e);

Loading…
Cancel
Save