diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CommonUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CommonUtils.java index 731cdaa719..2468e62ab0 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CommonUtils.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CommonUtils.java @@ -48,7 +48,7 @@ public class CommonUtils { envPath = envDefaultPath.getPath(); logger.debug("env path :{}", envPath); }else{ - envPath = System.getProperty("user.home") + File.separator + ".bash_profile"; + envPath = "/etc/profile"; } } diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/Preconditions.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/Preconditions.java index 32fd298a7d..1fe40b97e3 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/Preconditions.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/Preconditions.java @@ -18,266 +18,55 @@ package org.apache.dolphinscheduler.common.utils; /** - * A collection of static utility methods to validate input. + * utility methods for validating input * - *
This class is modelled after Google Guava's Preconditions class, and partly takes code
- * from that class. We add this code to here base in order to reduce external
- * dependencies.
*/
public final class Preconditions {
- // ------------------------------------------------------------------------
- // Null checks
- // ------------------------------------------------------------------------
+ private Preconditions() {}
/**
- * Ensures that the given object reference is not null.
- * Upon violation, a {@code NullPointerException} with no message is thrown.
+ * if obj is null will throw NPE
*
- * @param reference reference
+ * @param obj obj
* @param The error message is constructed from a template and an arguments array, after
- * a similar fashion as {@link String#format(String, Object...)}, but supporting only
- * {@code %s} as a placeholder.
- *
- * @param reference The object reference
- * @param errorMessageTemplate The message template for the {@code NullPointerException}
- * that is thrown if the check fails. The template substitutes its
- * {@code %s} placeholders with the error message arguments.
- * @param errorMessageArgs The arguments for the error message, to be inserted into the
- * message template for the {@code %s} placeholders.
- *
- * @param This method is taken quasi verbatim from the Guava Preconditions class.
- */
- private static String format( String template, Object... args) {
- final int numArgs = args == null ? 0 : args.length;
- template = String.valueOf(template); // null -> "null"
-
- // start substituting the arguments into the '%s' placeholders
- StringBuilder builder = new StringBuilder(template.length() + 16 * numArgs);
- int templateStart = 0;
- int i = 0;
- while (i < numArgs) {
- int placeholderStart = template.indexOf("%s", templateStart);
- if (placeholderStart == -1) {
- break;
- }
- builder.append(template.substring(templateStart, placeholderStart));
- builder.append(args[i++]);
- templateStart = placeholderStart + 2;
- }
- builder.append(template.substring(templateStart));
-
- // if we run out of placeholders, append the extra args in square braces
- if (i < numArgs) {
- builder.append(" [");
- builder.append(args[i++]);
- while (i < numArgs) {
- builder.append(", ");
- builder.append(args[i++]);
- }
- builder.append(']');
- }
-
- return builder.toString();
- }
-
- // ------------------------------------------------------------------------
-
- /** Private constructor to prevent instantiation. */
- private Preconditions() {}
}
diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/PreconditionsTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/PreconditionsTest.java
index 47b24bb93c..3bf13aa9f3 100644
--- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/PreconditionsTest.java
+++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/PreconditionsTest.java
@@ -33,11 +33,9 @@ public class PreconditionsTest {
*/
@Test
public void testCheckNotNull() throws Exception {
- String testReference = "test reference";
- //test reference is not null
+ String testReference = "test object";
Assert.assertEquals(testReference, Preconditions.checkNotNull(testReference));
- Assert.assertEquals(testReference,Preconditions.checkNotNull(testReference,"reference is null"));
- Assert.assertEquals(testReference,Preconditions.checkNotNull(testReference,"%s is null",testReference));
+ Assert.assertEquals(testReference,Preconditions.checkNotNull(testReference,"object is null"));
//test reference is null
try {
@@ -51,120 +49,19 @@ public class PreconditionsTest {
} catch (NullPointerException ex) {
assertNull(ex.getMessage());
}
- //test reference is null ,expect contains errorMessage
- try {
- Preconditions.checkNotNull(null,"reference is null");
- } catch (NullPointerException ex) {
- assertThat(ex.getMessage(), containsString("reference is null"));
- }
-
- try {
- Preconditions.checkNotNull("","reference is null");
- } catch (NullPointerException ex) {
- assertThat(ex.getMessage(), containsString("reference is null"));
- }
- //test reference is null ,expect contains errorMessageTemplate and errorMessageArgs
try {
- Preconditions.checkNotNull(null,"%s is null",testReference);
+ Preconditions.checkNotNull(null,"object is null");
} catch (NullPointerException ex) {
- assertThat(ex.getMessage(), containsString(testReference + " is null"));
+ assertThat(ex.getMessage(), containsString("object is null"));
}
try {
- Preconditions.checkNotNull("","%s is null",testReference);
+ Preconditions.checkNotNull("","object is null");
} catch (NullPointerException ex) {
- assertThat(ex.getMessage(), containsString(testReference + " is null"));
- }
- }
-
- /**
- * Test checkArgument
- */
- @Test
- public void testCheckArgument() throws Exception {
-
- int argument = 100;
- //boolean condition is true
- Preconditions.checkArgument(argument > 0 && argument < 200);
-
- //boolean condition is false
- try {
- Preconditions.checkArgument(argument > 0 && argument < 50);
- } catch (IllegalArgumentException ex) {
- assertNull(ex.getMessage());
- }
-
- //boolean condition is false ,expect contains errorMessage
- try {
- Preconditions.checkArgument(argument > 300, "argument is error");
- } catch (IllegalArgumentException ex) {
- assertThat(ex.getMessage(), containsString("argument is error"));
- }
-
- //boolean condition is false,expect contains errorMessageTemplate and errorMessageArgs
- try {
- Preconditions.checkArgument(argument > 0 && argument < 99, "argument %s is error",argument);
- } catch (IllegalArgumentException ex) {
- assertThat(ex.getMessage(), containsString( "argument " + argument + " is error"));
- }
- }
-
- /**
- * Test checkState
- */
- @Test
- public void testCheckState() throws Exception {
- int state = 1;
- //boolean condition is true
- Preconditions.checkState(state == 1);
- Preconditions.checkState(state > -1);
-
- //boolean condition is false
- try {
- Preconditions.checkState(state > 2);
- } catch (IllegalStateException ex) {
- assertNull(ex.getMessage());
- }
-
- //boolean condition is false ,expect contains errorMessage
- try {
- Preconditions.checkState(state < 1, "state is error");
- } catch (IllegalStateException ex) {
- assertThat(ex.getMessage(), containsString("state is error"));
+ assertThat(ex.getMessage(), containsString("object is null"));
}
- //boolean condition is false,expect contains errorMessageTemplate and errorMessageArgs
- try {
- Preconditions.checkState(state < -1 , "state %s is error",state);
- } catch (IllegalStateException ex) {
- assertThat(ex.getMessage(), containsString( "state " + state + " is error"));
- }
}
- /**
- * Test checkElementIndex
- */
- @Test
- public void testCheckElementIndex() throws Exception {
- int index = 2;
- int size = 30;
-
- //boolean condition is true
- Preconditions.checkElementIndex(index, size);
-
- //boolean condition is false
- try {
- Preconditions.checkElementIndex(-1, 10);
- } catch (IndexOutOfBoundsException ex) {
- assertThat(ex.getMessage(), containsString("Index: -1, Size: 10"));
- }
-
- //boolean condition is false ,expect contains errorMessage
- try {
- Preconditions.checkElementIndex(100, 50, "index is greater than size");
- } catch (IndexOutOfBoundsException ex) {
- assertThat(ex.getMessage(), containsString("index is greater than size Index: 100, Size: 50"));
- }
- }
}
diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/exceptions/RemotingException.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/exceptions/RemotingException.java
index 29d48db8f8..d774dc8b9e 100644
--- a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/exceptions/RemotingException.java
+++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/exceptions/RemotingException.java
@@ -26,69 +26,34 @@ public class RemotingException extends Exception {
super();
}
- /** Constructs a new runtime exception with the specified detail message.
- * The cause is not initialized, and may subsequently be initialized by a
- * call to {@link #initCause}.
+ /**
+ * Construct a new runtime exception with the detail message
*
- * @param message the detail message. The detail message is saved for
- * later retrieval by the {@link #getMessage()} method.
+ * @param message detail message
*/
public RemotingException(String message) {
super(message);
}
/**
- * Constructs a new runtime exception with the specified detail message and
- * cause. Note that the detail message associated with
- * {@code cause} is not automatically incorporated in
- * this runtime exception's detail message.
+ * Construct a new runtime exception with the detail message and cause
*
- * @param message the detail message (which is saved for later retrieval
- * by the {@link #getMessage()} method).
- * @param cause the cause (which is saved for later retrieval by the
- * {@link #getCause()} method). (A null value is
- * permitted, and indicates that the cause is nonexistent or
- * unknown.)
+ * @param message the detail message
+ * @param cause the cause
* @since 1.4
*/
public RemotingException(String message, Throwable cause) {
super(message, cause);
}
- /** Constructs a new runtime exception with the specified cause and a
- * detail message of (cause==null ? null : cause.toString())
- * (which typically contains the class and detail message of
- * cause). This constructor is useful for runtime exceptions
- * that are little more than wrappers for other throwables.
+ /**
+ * Construct a new runtime exception with throwable
*
- * @param cause the cause (which is saved for later retrieval by the
- * {@link #getCause()} method). (A null value is
- * permitted, and indicates that the cause is nonexistent or
- * unknown.)
- * @since 1.4
+ * @param cause the cause
*/
public RemotingException(Throwable cause) {
super(cause);
}
- /**
- * Constructs a new runtime exception with the specified detail
- * message, cause, suppression enabled or disabled, and writable
- * stack trace enabled or disabled.
- *
- * @param message the detail message.
- * @param cause the cause. (A {@code null} value is permitted,
- * and indicates that the cause is nonexistent or unknown.)
- * @param enableSuppression whether or not suppression is enabled
- * or disabled
- * @param writableStackTrace whether or not the stack trace should
- * be writable
- *
- * @since 1.7
- */
- protected RemotingException(String message, Throwable cause,
- boolean enableSuppression,
- boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- }
+
}
diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/future/ResponseFuture.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/future/ResponseFuture.java
index 2e3954f4bc..bbb32c76d1 100644
--- a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/future/ResponseFuture.java
+++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/future/ResponseFuture.java
@@ -170,21 +170,6 @@ public class ResponseFuture {
}
}
- @Override
- public String toString() {
- return "ResponseFuture{" +
- "opaque=" + opaque +
- ", timeoutMillis=" + timeoutMillis +
- ", invokeCallback=" + invokeCallback +
- ", releaseSemaphore=" + releaseSemaphore +
- ", latch=" + latch +
- ", beginTimestamp=" + beginTimestamp +
- ", responseCommand=" + responseCommand +
- ", sendOk=" + sendOk +
- ", cause=" + cause +
- '}';
- }
-
/**
* scan future table
*/
@@ -209,4 +194,19 @@ public class ResponseFuture {
}
}
}
+
+ @Override
+ public String toString() {
+ return "ResponseFuture{" +
+ "opaque=" + opaque +
+ ", timeoutMillis=" + timeoutMillis +
+ ", invokeCallback=" + invokeCallback +
+ ", releaseSemaphore=" + releaseSemaphore +
+ ", latch=" + latch +
+ ", beginTimestamp=" + beginTimestamp +
+ ", responseCommand=" + responseCommand +
+ ", sendOk=" + sendOk +
+ ", cause=" + cause +
+ '}';
+ }
}