You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampark.apache.org by be...@apache.org on 2023/02/14 03:25:50 UTC
[incubator-streampark] branch dev updated: Remove AssertUtils to fix license issues (#2327)
This is an automated email from the ASF dual-hosted git repository.
benjobs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
The following commit(s) were added to refs/heads/dev by this push:
new c956c935a Remove AssertUtils to fix license issues (#2327)
c956c935a is described below
commit c956c935ac397de10e4b0216fe57bee8c3e11dc1
Author: benjobs <be...@apache.org>
AuthorDate: Tue Feb 14 11:25:44 2023 +0800
Remove AssertUtils to fix license issues (#2327)
* Remove AssertUtils and ExceptionUtils to fix license issues
---
LICENSE | 2 -
dist-material/release-docs/LICENSE | 2 -
.../streampark/common/util/AssertUtils.scala | 486 ---------------------
.../streampark/common/util/ExceptionUtils.scala | 435 ------------------
.../org/apache/streampark/common/util/Utils.scala | 45 +-
.../console/base/exception/AlertException.java | 4 +-
.../console/base/exception/ApiDetailException.java | 6 +-
.../interceptor/UploadFileTypeInterceptor.java | 4 +-
.../streampark/console/base/util/CommonUtils.java | 8 +-
.../console/core/controller/ProjectController.java | 4 +-
.../console/core/runner/EnvInitializer.java | 9 +-
.../core/service/alert/impl/AlertServiceImpl.java | 4 +-
.../core/service/impl/AppBuildPipeServiceImpl.java | 9 +-
.../service/impl/ApplicationBackUpServiceImpl.java | 4 +-
.../core/service/impl/ApplicationServiceImpl.java | 47 +-
.../core/service/impl/FlinkSqlServiceImpl.java | 10 +-
.../core/service/impl/ProjectServiceImpl.java | 12 +-
.../core/service/impl/SavePointServiceImpl.java | 4 +-
.../core/service/impl/SqlCompleteServiceImpl.java | 4 +-
.../console/core/task/FlinkRESTAPIWatcher.java | 4 +-
.../console/system/controller/UserController.java | 6 +-
.../system/service/impl/MemberServiceImpl.java | 14 +-
.../system/service/impl/RoleServiceImpl.java | 4 +-
.../system/service/impl/TeamServiceImpl.java | 4 +-
.../system/service/impl/UserServiceImpl.java | 9 +-
.../flink/client/trait/YarnSubmitTrait.scala | 7 +-
.../connector/hbase/source/HBaseJavaSource.java | 4 +-
.../flink/connector/jdbc/sink/JdbcJavaSink.java | 4 +-
.../connector/jdbc/source/JdbcJavaSource.java | 4 +-
.../connector/mongo/source/MongoJavaSource.java | 6 +-
.../streampark/flink/core/FlinkSqlValidator.scala | 6 +-
31 files changed, 133 insertions(+), 1038 deletions(-)
diff --git a/LICENSE b/LICENSE
index 37a339474..069b0d8d2 100644
--- a/LICENSE
+++ b/LICENSE
@@ -211,5 +211,3 @@ The text of each license is the standard Apache 2.0 license.
mvnw files from https://github.com/apache/maven-wrapper Apache 2.0
streampark-console/streampark-console-service/src/main/assembly/bin/setclasspath.sh from https://github.com/apache/tomcat
-streampark-common/src/main/scala/org/apache/streampark/common/util/ExceptionUtils.scala from https://github.com/apache/flink
-streampark-common/src/main/scala/org/apache/streampark/common/util/AssertUtils.scala from https://github.com/spring-projects/spring-framework
diff --git a/dist-material/release-docs/LICENSE b/dist-material/release-docs/LICENSE
index 03e3afbb7..076604b61 100644
--- a/dist-material/release-docs/LICENSE
+++ b/dist-material/release-docs/LICENSE
@@ -584,8 +584,6 @@ The text of each license is the standard Apache 2.0 license. https://www.apache.
https://maven.apache.org/wrapper Apache-2.0
mvnw files from https://github.com/apache/maven-wrapper Apache 2.0
streampark-console/streampark-console-service/src/main/assembly/bin/setclasspath.sh from https://github.com/apache/tomcat
- streampark-common/src/main/scala/org/apache/streampark/common/util/ExceptionUtils.scala from https://github.com/apache/flink
- streampark-common/src/main/scala/org/apache/streampark/common/util/AssertUtils.scala from https://github.com/spring-projects/spring-framework
========================================================================
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/AssertUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/AssertUtils.scala
deleted file mode 100644
index 6b24b9e54..000000000
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/AssertUtils.scala
+++ /dev/null
@@ -1,486 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.streampark.common.util
-
-import java.util
-
-object AssertUtils {
-
- /**
- * Assert a boolean expression, throwing <code>IllegalArgumentException</code> if the test result
- * is <code>false</code>.
- *
- * <pre class="code">AssertUtil.isTrue(i > 0, "The value must be greater than zero");</pre>
- *
- * @param expression a boolean expression
- * @param message the exception message to use if the assertion fails
- * @throws IllegalArgumentException if expression is <code>false</code>
- */
- def isTrue(expression: Boolean, message: String): Unit = {
- if (!expression) {
- throw new IllegalArgumentException(message)
- }
- }
-
- /**
- * Assert a boolean expression, throwing <code>IllegalArgumentException</code> if the test result
- * is <code>false</code>.
- *
- * <pre class="code">AssertUtil.isTrue(i > 0);</pre>
- *
- * @param expression a boolean expression
- * @throws IllegalArgumentException if expression is <code>false</code>
- */
- def isTrue(expression: Boolean): Unit = {
- isTrue(expression, "[Assertion failed] - this expression must be true")
- }
-
- /**
- * Assert a boolean expression, throwing <code>IllegalArgumentException</code> if the test result
- * is <code>true</code>.
- *
- * <pre class="code">AssertUtil.trueException(i > 0, "The value must be greater than zero");
- * </pre>
- *
- * @param expression a boolean expression
- * @throws IllegalArgumentException if expression is <code>false</code>
- */
- def trueException(expression: Boolean): Unit = {
- trueException(expression, "[Assertion failed] - when expression is true,throw exception")
- }
-
- def trueException(expression: Boolean, message: String): Unit = {
- if (expression) {
- throw new IllegalArgumentException(message)
- }
- }
-
- /**
- * Assert a boolean expression, throwing <code>IllegalArgumentException</code> if the test result
- * is <code>false</code>.
- *
- * <pre class="code">AssertUtil.falseException(i > 0, "The value must be greater than zero");
- * </pre>
- *
- * @param expression a boolean expression
- * @throws IllegalArgumentException if expression is <code>false</code>
- */
- def falseException(expression: Boolean): Unit = {
- falseException(expression, "[Assertion failed] - when expression is false,throw exception")
- }
-
- /**
- * Assert a boolean expression, throwing <code>IllegalArgumentException</code> if the test result
- * is <code>false</code>.
- *
- * <pre class="code">AssertUtil.falseException(i > 0, "The value must be greater than zero");
- * </pre>
- *
- * @param expression a boolean expression
- * @param message the exception message to use if the assertion fails
- * @throws IllegalArgumentException if expression is <code>false</code>
- */
- def falseException(expression: Boolean, message: String): Unit = {
- if (!expression) {
- throw new IllegalArgumentException(message)
- }
- }
-
- /**
- * Assert that an object is <code>null</code> .
- *
- * <pre class="code">AssertUtil.isNull(value, "The value must be null");</pre>
- *
- * @param object the object to check
- * @param message the exception message to use if the assertion fails
- * @throws IllegalArgumentException if the object is not <code>null</code>
- */
- def isNull(obj: Any, message: String): Unit = {
- if (obj != null) {
- throw new IllegalArgumentException(message)
- }
- }
-
- /**
- * Assert that an object is <code>null</code> .
- *
- * <pre class="code">AssertUtil.isNull(value);</pre>
- *
- * @param obj the object to check
- * @throws IllegalArgumentException if the object is not <code>null</code>
- */
- def isNull(obj: Any): Unit = {
- isNull(obj, "[Assertion failed] - the object argument must be null")
- }
-
- /**
- * Assert that an object is not <code>null</code> .
- *
- * <pre class="code">AssertUtil.notNull(clazz, "The class must not be null");</pre>
- *
- * @param object the object to check
- * @param message the exception message to use if the assertion fails
- * @throws IllegalArgumentException if the object is <code>null</code>
- */
- def notNull(obj: Any, message: String): Unit = {
- if (obj == null) {
- throw new IllegalArgumentException(message)
- }
- }
-
- def notNull(obj: Any*): Unit = {
- notNull(obj, "[Assertion failed] - this argument is required; it must not be null")
- for (i <- 0 until obj.length) {
- notNull(obj(i), "[Assertion failed] - this argument index of " + i + " is required; it must not be null")
- }
- }
-
- /**
- * Assert that an object is not <code>null</code> .
- *
- * <pre class="code">AssertUtil.notNull(clazz);</pre>
- *
- * @param object the object to check
- * @throws IllegalArgumentException if the object is <code>null</code>
- */
- def notNull(obj: Any): Unit = {
- notNull(obj, "[Assertion failed] - this argument is required; it must not be null")
- }
-
- /**
- * Assert that the given String is not empty; that is, it must not be <code>null</code> and not
- * the empty String.
- *
- * <pre class="code">AssertUtil.hasLength(name, "Name must not be empty");</pre>
- *
- * @param text the String to check
- * @param message the exception message to use if the assertion fails
- * @see org.springframework.util.StringUtils#hasLength
- */
- def hasLength(text: String, message: String): Unit = {
- if (Utils.isEmpty(text)) {
- throw new IllegalArgumentException(message)
- }
- }
-
- /**
- * Assert that the given String is not empty; that is, it must not be <code>null</code> and not
- * the empty String.
- *
- * <pre class="code">AssertUtil.hasLength(name);</pre>
- *
- * @param text the String to check
- */
- def hasLength(text: String): Unit = {
- hasLength(text, "[Assertion failed] - this String argument must have length; it must not be null or empty")
- }
-
- /**
- * Assert that the given String has valid text content; that is, it must not be <code>null</code>
- * and must contain at least one non-whitespace character.
- *
- * <pre class="code">AssertUtil.hasText(name, "'name' must not be empty");</pre>
- *
- * @param text the String to check
- * @param message the exception message to use if the assertion fails
- */
- def hasText(text: String, message: String): Unit = {
- if (Utils.isEmpty(text)) {
- throw new IllegalArgumentException(message)
- }
- }
-
- /**
- * Assert that the given String has valid text content; that is, it must not be <code>null</code>
- * and must contain at least one non-whitespace character.
- *
- * <pre class="code">AssertUtil.hasText(name, "'name' must not be empty");</pre>
- *
- * @param text the String to check
- */
- def hasText(text: String): Unit = {
- hasText(text, "[Assertion failed] - this String argument must have text; it must not be null, empty, or blank")
- }
-
- /**
- * Assert that the given text does not contain the given substring.
- *
- * <pre class="code">AssertUtil.doesNotContain(name, "rod", "Name must not contain 'rod'");</pre>
- *
- * @param textToSearch the text to search
- * @param substring the substring to find within the text
- * @param message the exception message to use if the assertion fails
- */
- def doesNotContain(textToSearch: String, substring: String, message: String): Unit = {
- if (Utils.notEmpty(textToSearch) && Utils.notEmpty(substring) && textToSearch.indexOf(substring) != -1) {
- throw new IllegalArgumentException(message)
- }
- }
-
- /**
- * Assert that the given text does not contain the given substring.
- *
- * <pre class="code">AssertUtil.doesNotContain(name, "rod");</pre>
- *
- * @param textToSearch the text to search
- * @param substring the substring to find within the text
- */
- def doesNotContain(textToSearch: String, substring: String): Unit = {
- doesNotContain(textToSearch, substring, "[Assertion failed] - this String argument must not contain the substring [" + substring + "]")
- }
-
- /**
- * Assert that an array has elements; that is, it must not be <code>null</code> and must have at
- * least one element.
- *
- * <pre class="code">AssertUtil.notEmpty(array, "The array must have elements");</pre>
- *
- * @param array the array to check
- * @param message the exception message to use if the assertion fails
- * @throws IllegalArgumentException if the object array is <code>null</code> or has no elements
- */
- def notEmpty(array: Array[AnyRef], message: String): Unit = {
- if (Utils.isEmpty(array)) {
- throw new IllegalArgumentException(message)
- }
- }
-
- /**
- * Assert that an array has elements; that is, it must not be <code>null</code> and must have at
- * least one element.
- *
- * <pre class="code">AssertUtil.notEmpty(array);</pre>
- *
- * @param array the array to check
- * @throws IllegalArgumentException if the object array is <code>null</code> or has no elements
- */
- def notEmpty(array: Array[AnyRef]): Unit = {
- notEmpty(array, "[Assertion failed] - this array must not be empty: it must contain at least 1 element")
- }
-
- /**
- * Assert that an array has no null elements. Note: Does not complain if the array is empty!
- *
- * <pre class="code">AssertUtil.noNullElements(array, "The array must have non-null elements");
- * </pre>
- *
- * @param array the array to check
- * @param message the exception message to use if the assertion fails
- * @throws IllegalArgumentException if the object array contains a <code>null</code> element
- */
- def noNullElements(array: Array[AnyRef], message: String): Unit = {
- if (array != null) for (i <- array.indices) {
- if (array(i) == null) {
- throw new IllegalArgumentException(message)
- }
- }
- }
-
- /**
- * Assert that an array has no null elements. Note: Does not complain if the array is empty!
- *
- * <pre class="code">AssertUtil.noNullElements(array);</pre>
- *
- * @param array the array to check
- * @throws IllegalArgumentException if the object array contains a <code>null</code> element
- */
- def noNullElements(array: Array[AnyRef]): Unit = {
- noNullElements(array, "[Assertion failed] - this array must not contain any null elements")
- }
-
- /**
- * Assert that a collection has elements; that is, it must not be <code>null</code> and must have
- * at least one element.
- *
- * <pre class="code">AssertUtil.notEmpty(collection, "Collection must have elements");</pre>
- *
- * @param collection the collection to check
- * @param message the exception message to use if the assertion fails
- * @throws IllegalArgumentException if the collection is <code>null</code> or has no elements
- */
- def notEmpty(collection: util.Collection[_], message: String): Unit = {
- if (Utils.isEmpty(collection)) {
- throw new IllegalArgumentException(message)
- }
- }
-
- /**
- * Assert that a collection has elements; that is, it must not be <code>null</code> and must have
- * at least one element.
- *
- * <pre class="code">AssertUtil.notEmpty(collection, "Collection must have elements");</pre>
- *
- * @param collection the collection to check
- * @throws IllegalArgumentException if the collection is <code>null</code> or has no elements
- */
- def notEmpty(collection: util.Collection[_]): Unit = {
- notEmpty(collection, "[Assertion failed] - this collection must not be empty: it must contain at least 1 element")
- }
-
- /**
- * Assert that a Map has entries; that is, it must not be <code>null</code> and must have at least
- * one entry.
- *
- * <pre class="code">AssertUtil.notEmpty(map, "Map must have entries");</pre>
- *
- * @param map the map to check
- * @param message the exception message to use if the assertion fails
- * @throws IllegalArgumentException if the map is <code>null</code> or has no entries
- */
- def notEmpty(map: util.Map[_, _], message: String): Unit = {
- if (Utils.isEmpty(map)) {
- throw new IllegalArgumentException(message)
- }
- }
-
- /**
- * Assert that a Map has entries; that is, it must not be <code>null</code> and must have at least
- * one entry.
- *
- * <pre class="code">AssertUtil.notEmpty(map);</pre>
- *
- * @param map the map to check
- * @throws IllegalArgumentException if the map is <code>null</code> or has no entries
- */
- def notEmpty(map: util.Map[_, _]): Unit = {
- notEmpty(map, "[Assertion failed] - this map must not be empty; it must contain at least one entry")
- }
-
- /**
- * Assert that <code>superType.isAssignableFrom(subType)</code> is <code>true</code>.
- *
- * <pre class="code">AssertUtil.isAssignable(Number.class, myClass);</pre>
- *
- * @param superType the super type to check
- * @param subType the sub type to check
- * @throws IllegalArgumentException if the classes are not assignable
- */
- def isAssignable(superType: Class[_], subType: Class[_]): Unit = {
- isAssignable(superType, subType, "")
- }
-
- /**
- * Assert that <code>superType.isAssignableFrom(subType)</code> is <code>true</code>.
- *
- * <pre class="code">AssertUtil.isAssignable(Number.class, myClass);</pre>
- *
- * @param superType the super type to check against
- * @param subType the sub type to check
- * @param message a message which will be prepended to the message produced by the function
- * itself, and which may be used to provide context. It should normally end in a ": " or ". "
- * so that the function generate message looks ok when prepended to it.
- * @throws IllegalArgumentException if the classes are not assignable
- */
- def isAssignable(superType: Class[_], subType: Class[_], message: String): Unit = {
- notNull(superType, "Type to check against must not be null")
- if (subType == null || !superType.isAssignableFrom(subType)) {
- throw new IllegalArgumentException(message + subType + " is not assignable to " + superType)
- }
- }
-
- /**
- * Assert a boolean expression, throwing <code>IllegalStateException</code> if the test result is
- * <code>false</code>. Call isTrue if you wish to throw IllegalArgumentException on an assertion
- * failure.
- *
- * <pre class="code">
- * AssertUtil.state(id == null, "The id property must not already be initialized");</pre>
- *
- * @param expression a boolean expression
- * @param message the exception message to use if the assertion fails
- * @throws IllegalStateException if expression is <code>false</code>
- */
- def state(expression: Boolean, message: String): Unit = {
- if (!expression) {
- throw new IllegalStateException(message)
- }
- }
-
- /**
- * Assert a boolean expression, throwing {@link IllegalStateException} if the test result is
- * <code>false</code>.
- *
- * <p>Call {@link #isTrue ( boolean )} if you wish to throw {@link IllegalArgumentException} on an
- * assertion failure.
- *
- * <pre class="code">AssertUtil.state(id == null);</pre>
- *
- * @param expression a boolean expression
- * @throws IllegalStateException if the supplied expression is <code>false</code>
- */
- def state(expression: Boolean): Unit = {
- state(expression, "[Assertion failed] - this state invariant must be true")
- }
-
- /**
- * Ensures that an object reference passed as a parameter to the calling method is not null.
- *
- * @param reference an object reference
- * @return the non-null reference that was validated
- * @throws NullPointerException if {@code reference} is null
- */
- def checkNotNull[T](reference: T): T = {
- if (reference == null) {
- throw new NullPointerException
- }
- reference
- }
-
- /**
- * Ensures that an object reference passed as a parameter to the calling method is not null.
- *
- * @param reference an object reference
- * @param errorMessage the exception message to use if the check fails; will be converted to a
- * string using {@link String# valueOf ( Object )}
- * @return the non-null reference that was validated
- * @throws NullPointerException if {@code reference} is null
- */
- def checkNotNull[T](reference: T, errorMessage: Any): T = {
- if (reference == null) {
- throw new NullPointerException(String.valueOf(errorMessage))
- }
- reference
- }
-
- /**
- * Ensures the truth of an expression involving one or more parameters to the calling method.
- *
- * @param expression a boolean expression
- * @throws IllegalArgumentException if {@code expression} is false
- */
- def checkArgument(expression: Boolean): Unit = {
- if (!expression) {
- throw new IllegalArgumentException
- }
- }
-
- /**
- * Ensures the truth of an expression involving one or more parameters to the calling method.
- *
- * @param expression a boolean expression
- * @param errorMessage the exception message to use if the check fails; will be converted to a
- * string using {@link String# valueOf ( Object )}
- * @throws IllegalArgumentException if {@code expression} is false
- */
- def checkArgument(expression: Boolean, errorMessage: Any): Unit = {
- if (!expression) {
- throw new IllegalArgumentException(String.valueOf(errorMessage))
- }
- }
-
-}
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/ExceptionUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/ExceptionUtils.scala
deleted file mode 100644
index 9a665af2f..000000000
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/ExceptionUtils.scala
+++ /dev/null
@@ -1,435 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.streampark.common.util
-
-import java.io.{IOException, PrintWriter, StringWriter}
-import java.util
-import java.util.{Optional, StringTokenizer}
-import java.util.concurrent.{CompletionException, ExecutionException}
-import java.util.function.Predicate
-import javax.annotation.Nullable
-
-import org.apache.commons.lang3.ArrayUtils
-
-/**
- * A collection of utility functions for dealing with exceptions and exception workflows.
- */
-object ExceptionUtils {
-
- /** The stringified representation of a null exception reference. */
- val STRINGIFIED_NULL_EXCEPTION = "(null)"
-
- /**
- * Makes a string representation of the exception's stack trace, or "(null)", if the
- * exception is null.
- *
- * <p>This method makes a best effort and never fails.
- *
- * @param e The exception to stringify.
- * @return A string with exception name and call stack.
- */
- def stringifyException(e: Throwable): String = {
- if (e == null) return STRINGIFIED_NULL_EXCEPTION
- try {
- val stm = new StringWriter
- val wrt = new PrintWriter(stm)
- e.printStackTrace(wrt)
- wrt.close()
- stm.toString
- } catch {
- case _: Throwable => e.getClass.getName + " (error while printing stack trace)"
- }
- }
-
- /**
- * Checks whether the given exception indicates a situation that may leave the
- * JVM in a corrupted state, meaning a state where continued normal operation can only be
- * guaranteed via clean process restart.
- *
- * <p>Currently considered fatal exceptions are Virtual Machine errors indicating
- * that the JVM is corrupted, like {@link InternalError}, {@link UnknownError},
- * and {@link java.util.zip.ZipError} (a special case of InternalError).
- * The {@link ThreadDeath} exception is also treated as a fatal error, because when
- * a thread is forcefully stopped, there is a high chance that parts of the system
- * are in an inconsistent state.
- *
- * @param t The exception to check.
- * @return True, if the exception is considered fatal to the JVM, false otherwise.
- */
- def isJvmFatalError(t: Throwable): Boolean = t.isInstanceOf[InternalError] || t.isInstanceOf[UnknownError] || t.isInstanceOf[ThreadDeath]
-
- /**
- * Checks whether the given exception indicates a situation that may leave the
- * JVM in a corrupted state, or an out-of-memory error.
- *
- * <p>See {@link ExceptionUtils# isJvmFatalError ( Throwable )} for a list of fatal JVM errors.
- * This method additionally classifies the {@link OutOfMemoryError} as fatal, because it
- * may occur in any thread (not the one that allocated the majority of the memory) and thus
- * is often not recoverable by destroying the particular thread that threw the exception.
- *
- * @param t The exception to check.
- * @return True, if the exception is fatal to the JVM or and OutOfMemoryError, false otherwise.
- */
- def isJvmFatalOrOutOfMemoryError(t: Throwable): Boolean = isJvmFatalError(t) || t.isInstanceOf[OutOfMemoryError]
-
- /**
- * Tries to enrich the passed exception with additional information.
- *
- * <p>This method improves error message for direct and metaspace {@link OutOfMemoryError}.
- * It adds description of possible causes and ways of resolution.
- *
- * @param exception exception to enrich if not {@code null}
- * @return the enriched exception or the original if no additional information could be added;
- * {@code null} if the argument was {@code null}
- */
- @Nullable def tryEnrichOutOfMemoryError(
- @Nullable exception: Throwable,
- jvmMetaspaceOomNewErrorMessage: String,
- jvmDirectOomNewErrorMessage: String): Throwable = {
- val isOom = exception.isInstanceOf[OutOfMemoryError]
- if (!isOom) return exception
- val oom = exception.asInstanceOf[OutOfMemoryError]
- if (isMetaspaceOutOfMemoryError(oom)) return changeOutOfMemoryErrorMessage(oom, jvmMetaspaceOomNewErrorMessage)
- else if (isDirectOutOfMemoryError(oom)) return changeOutOfMemoryErrorMessage(oom, jvmDirectOomNewErrorMessage)
- oom
- }
-
- /**
- * Rewrites the error message of a {@link OutOfMemoryError}.
- *
- * @param oom original {@link OutOfMemoryError}
- * @param newMessage new error message
- * @return the origianl {@link OutOfMemoryError} if it already has the new error message or
- * a new {@link OutOfMemoryError} with the new error message
- */
- private def changeOutOfMemoryErrorMessage(oom: OutOfMemoryError, newMessage: String): OutOfMemoryError = {
- if (oom.getMessage == newMessage) return oom
- val newError = new OutOfMemoryError(newMessage)
- newError.initCause(oom.getCause)
- newError.setStackTrace(oom.getStackTrace)
- newError
- }
-
- /**
- * Checks whether the given exception indicates a JVM metaspace out-of-memory error.
- *
- * @param t The exception to check.
- * @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
- */
- def isMetaspaceOutOfMemoryError(@Nullable t: Throwable): Boolean = isOutOfMemoryErrorWithMessageStartingWith(t, "Metaspace")
-
- /**
- * Checks whether the given exception indicates a JVM direct out-of-memory error.
- *
- * @param t The exception to check.
- * @return True, if the exception is the direct {@link OutOfMemoryError}, false otherwise.
- */
- def isDirectOutOfMemoryError(@Nullable t: Throwable): Boolean = isOutOfMemoryErrorWithMessageStartingWith(t, "Direct buffer memory")
-
- private def isOutOfMemoryErrorWithMessageStartingWith(@Nullable t: Throwable, prefix: String) = { // the exact matching of the class is checked to avoid matching any custom subclasses of OutOfMemoryError
- // as we are interested in the original exceptions, generated by JVM.
- isOutOfMemoryError(t) && t.getMessage != null && t.getMessage.startsWith(prefix)
- }
-
- private def isOutOfMemoryError(@Nullable t: Throwable) = t != null && (t.getClass eq classOf[OutOfMemoryError])
-
- /**
- * Rethrows the given {@code Throwable}, if it represents an error that is fatal to the JVM.
- * See {@link ExceptionUtils# isJvmFatalError ( Throwable )} for a definition of fatal errors.
- *
- * @param t The Throwable to check and rethrow.
- */
- def rethrowIfFatalError(t: Throwable): Unit = {
- if (isJvmFatalError(t)) throw t.asInstanceOf[Error]
- }
-
- /**
- * Rethrows the given {@code Throwable}, if it represents an error that is fatal to the JVM
- * or an out-of-memory error. See {@link ExceptionUtils# isJvmFatalError ( Throwable )} for a
- * definition of fatal errors.
- *
- * @param t The Throwable to check and rethrow.
- */
- def rethrowIfFatalErrorOrOOM(t: Throwable): Unit = {
- if (isJvmFatalError(t) || t.isInstanceOf[OutOfMemoryError]) throw t.asInstanceOf[Error]
- }
-
- /**
- * Adds a new exception as a {@link Throwable# addSuppressed ( Throwable ) suppressed exception}
- * to a prior exception, or returns the new exception, if no prior exception exists.
- *
- * <pre>{@code
- *
- * public void closeAllThings() throws Exception {
- * Exception ex = null;
- * try {
- * component.shutdown();
- * } catch (Exception e) {
- * ex = firstOrSuppressed(e, ex);
- * }
- * try {
- * anotherComponent.stop();
- * } catch (Exception e) {
- * ex = firstOrSuppressed(e, ex);
- * }
- * try {
- * lastComponent.shutdown();
- * } catch (Exception e) {
- * ex = firstOrSuppressed(e, ex);
- * }
- *
- * if (ex != null) {
- * throw ex;
- * }
- * }
- * }</pre>
- *
- * @param newException The newly occurred exception
- * @param previous The previously occurred exception, possibly null.
- *
- * @return The new exception, if no previous exception exists, or the previous exception with the
- * new exception in the list of suppressed exceptions.
- */
- def firstOrSuppressed[T <: Throwable](newException: T, @Nullable previous: T): T = {
- require(newException != null, "newException")
- if (previous == null) newException
- else {
- previous.addSuppressed(newException)
- previous
- }
- }
-
- /**
- * Throws the given {@code Throwable} in scenarios where the signatures do not allow you to
- * throw an arbitrary Throwable. Errors and RuntimeExceptions are thrown directly, other exceptions
- * are packed into runtime exceptions
- *
- * @param t The throwable to be thrown.
- */
- def rethrow(t: Throwable): Unit = {
- if (t.isInstanceOf[Error]) throw t.asInstanceOf[Error]
- else if (t.isInstanceOf[RuntimeException]) throw t.asInstanceOf[RuntimeException]
- else throw new RuntimeException(t)
- }
-
- /**
- * Throws the given {@code Throwable} in scenarios where the signatures do not allow you to
- * throw an arbitrary Throwable. Errors and RuntimeExceptions are thrown directly, other exceptions
- * are packed into a parent RuntimeException.
- *
- * @param t The throwable to be thrown.
- * @param parentMessage The message for the parent RuntimeException, if one is needed.
- */
- def rethrow(t: Throwable, parentMessage: String): Unit = {
- if (t.isInstanceOf[Error]) throw t.asInstanceOf[Error]
- else if (t.isInstanceOf[RuntimeException]) throw t.asInstanceOf[RuntimeException]
- else throw new RuntimeException(parentMessage, t)
- }
-
- /**
- * Throws the given {@code Throwable} in scenarios where the signatures do allow to
- * throw a Exception. Errors and Exceptions are thrown directly, other "exotic"
- * subclasses of Throwable are wrapped in an Exception.
- *
- * @param t The throwable to be thrown.
- * @param parentMessage The message for the parent Exception, if one is needed.
- */
- @throws[Exception]
- def rethrowException(t: Throwable, parentMessage: String): Unit = {
- if (t.isInstanceOf[Error]) throw t.asInstanceOf[Error]
- else if (t.isInstanceOf[Exception]) throw t.asInstanceOf[Exception]
- else throw new Exception(parentMessage, t)
- }
-
- /**
- * Throws the given {@code Throwable} in scenarios where the signatures do allow to
- * throw a Exception. Errors and Exceptions are thrown directly, other "exotic"
- * subclasses of Throwable are wrapped in an Exception.
- *
- * @param t The throwable to be thrown.
- */
- @throws[Exception]
- def rethrowException(t: Throwable): Unit = {
- if (t.isInstanceOf[Error]) throw t.asInstanceOf[Error]
- else if (t.isInstanceOf[Exception]) throw t.asInstanceOf[Exception]
- else throw new Exception(t.getMessage, t)
- }
-
- /**
- * Tries to throw the given exception if not null.
- *
- * @param e exception to throw if not null.
- * @throws Exception
- */
- @throws[Exception]
- def tryRethrowException(@Nullable e: Exception): Unit = {
- if (e != null) throw e
- }
-
- /**
- * Tries to throw the given {@code Throwable} in scenarios where the signatures allows only IOExceptions
- * (and RuntimeException and Error). Throws this exception directly, if it is an IOException,
- * a RuntimeException, or an Error. Otherwise does nothing.
- *
- * @param t The Throwable to be thrown.
- */
- @throws[IOException]
- def tryRethrowIOException(t: Throwable): Unit = {
- if (t.isInstanceOf[IOException]) throw t.asInstanceOf[IOException]
- else if (t.isInstanceOf[RuntimeException]) throw t.asInstanceOf[RuntimeException]
- else if (t.isInstanceOf[Error]) throw t.asInstanceOf[Error]
- }
-
- /**
- * Re-throws the given {@code Throwable} in scenarios where the signatures allows only IOExceptions
- * (and RuntimeException and Error).
- *
- * <p>Throws this exception directly, if it is an IOException, a RuntimeException, or an Error. Otherwise it
- * wraps it in an IOException and throws it.
- *
- * @param t The Throwable to be thrown.
- */
- @throws[IOException]
- def rethrowIOException(t: Throwable): Unit = {
- if (t.isInstanceOf[IOException]) throw t.asInstanceOf[IOException]
- else if (t.isInstanceOf[RuntimeException]) throw t.asInstanceOf[RuntimeException]
- else if (t.isInstanceOf[Error]) throw t.asInstanceOf[Error]
- else throw new IOException(t.getMessage, t)
- }
-
- /**
- * Checks whether a throwable chain contains a specific type of exception and returns it.
- *
- * @param throwable the throwable chain to check.
- * @param searchType the type of exception to search for in the chain.
- * @return Optional throwable of the requested type if available, otherwise empty
- */
- def findThrowable[T <: Throwable](throwable: Throwable, searchType: Class[T]): Optional[T] = {
- if (throwable == null || searchType == null) Optional.empty[T]
- else {
- var t = throwable
- var r: Optional[T] = null
- while (t != null && r == null) {
- if (searchType.isAssignableFrom(t.getClass)) {
- r = Optional.of(searchType.cast(t))
- } else t = t.getCause
- }
- r
- }
- }
-
- /**
- * Checks whether a throwable chain contains an exception matching a predicate and returns it.
- *
- * @param throwable the throwable chain to check.
- * @param predicate the predicate of the exception to search for in the chain.
- * @return Optional throwable of the requested type if available, otherwise empty
- */
- def findThrowable(throwable: Throwable, predicate: Predicate[Throwable]): Optional[Throwable] = {
- if (throwable == null || predicate == null) Optional.empty[Throwable]
- else {
- var t = throwable
- var r: Optional[Throwable] = null
- while (t != null && r == null) {
- if (predicate.test(t)) {
- r = Optional.of(t)
- } else t = t.getCause
- }
- r
- }
- }
-
- /**
- * Checks whether a throwable chain contains a specific error message and returns the corresponding throwable.
- *
- * @param throwable the throwable chain to check.
- * @param searchMessage the error message to search for in the chain.
- * @return Optional throwable containing the search message if available, otherwise empty
- */
- def findThrowableWithMessage(throwable: Throwable, searchMessage: String): Optional[Throwable] = {
- if (throwable == null || searchMessage == null) Optional.empty[Throwable]
- else {
- var t = throwable
- var r: Optional[Throwable] = null
- while (t != null && r == null) {
- if (t.getMessage != null && t.getMessage.contains(searchMessage)) {
- r = Optional.of(t)
- } else t = t.getCause
- }
- r
- }
- }
-
- /**
- * Unpacks an {@link ExecutionException} and returns its cause. Otherwise the given
- * Throwable is returned.
- *
- * @param throwable to unpack if it is an ExecutionException
- * @return Cause of ExecutionException or given Throwable
- */
- def stripExecutionException(throwable: Throwable): Throwable = stripException(throwable, classOf[ExecutionException])
-
- /**
- * Unpacks an {@link CompletionException} and returns its cause. Otherwise the given
- * Throwable is returned.
- *
- * @param throwable to unpack if it is an CompletionException
- * @return Cause of CompletionException or given Throwable
- */
- def stripCompletionException(throwable: Throwable): Throwable = stripException(throwable, classOf[CompletionException])
-
- /**
- * Unpacks an specified exception and returns its cause. Otherwise the given
- * {@link Throwable} is returned.
- *
- * @param throwableToStrip to strip
- * @param typeToStrip type to strip
- * @return Unpacked cause or given Throwable if not packed
- */
- def stripException(throwableToStrip: Throwable, typeToStrip: Class[_ <: Throwable]): Throwable = {
- var throwable: Throwable = null
- while (typeToStrip.isAssignableFrom(throwableToStrip.getClass()) && throwableToStrip.getCause() != null) {
- throwable = throwableToStrip.getCause()
- }
- throwable
- }
-
- /**
- * Checks whether the given exception is a {@link InterruptedException} and sets
- * the interrupted flag accordingly.
- *
- * @param e to check whether it is an {@link InterruptedException}
- */
- def checkInterrupted(e: Throwable): Unit = {
- if (e.isInstanceOf[InterruptedException]) Thread.currentThread.interrupt()
- }
-
- /**
- * @param stackTrace
- * @return
- */
- def getStackFrames(stackTrace: String): Array[String] = {
- val linebreak: String = System.lineSeparator
- val frames: StringTokenizer = new StringTokenizer(stackTrace, linebreak)
- val list: util.List[String] = new util.ArrayList[String]
- while (frames.hasMoreTokens) {
- list.add(frames.nextToken)
- }
- list.toArray(ArrayUtils.EMPTY_STRING_ARRAY)
- }
-
-}
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/Utils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/Utils.scala
index 5e8b34e50..a83314d93 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/Utils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/Utils.scala
@@ -16,23 +16,32 @@
*/
package org.apache.streampark.common.util
-import java.io.{BufferedInputStream, File, FileInputStream, IOException}
+import java.io.{BufferedInputStream, File, FileInputStream, IOException, PrintWriter, StringWriter}
import java.net.URL
-import java.util.{jar, Collection => JavaCollection, Map => JavaMap, Properties, UUID}
+import java.util.{Properties, UUID, jar, Collection => JavaCollection, Map => JavaMap}
import java.util.jar.{JarFile, JarInputStream}
-
import scala.collection.JavaConversions._
import scala.util.{Failure, Success, Try}
-
import org.apache.commons.lang3.StringUtils
object Utils {
private[this] lazy val OS = System.getProperty("os.name").toLowerCase
+ def notNull(obj: Any, message: String): Unit = {
+ if (obj == null) {
+ throw new NullPointerException(message)
+ }
+ }
+
+ def notNull(obj: Any): Unit = {
+ notNull(obj, "this argument is required; it must not be null")
+ }
+
def notEmpty(elem: Any): Boolean = {
elem match {
case null => false
+ case x if x.isInstanceOf[Array[_]] => elem.asInstanceOf[Array[_]].nonEmpty
case x if x.isInstanceOf[CharSequence] => elem.toString.trim.nonEmpty
case x if x.isInstanceOf[Traversable[_]] => x.asInstanceOf[Traversable[_]].nonEmpty
case x if x.isInstanceOf[Iterable[_]] => x.asInstanceOf[Iterable[_]].nonEmpty
@@ -44,14 +53,20 @@ object Utils {
def isEmpty(elem: Any): Boolean = !notEmpty(elem)
- def uuid(): String = UUID.randomUUID().toString.replaceAll("-", "")
+ def required(expression: Boolean): Unit = {
+ if (!expression) {
+ throw new IllegalArgumentException
+ }
+ }
- def require(requirement: Boolean, message: String): Unit = {
- if (!requirement) {
- throw new IllegalArgumentException(s"requirement failed: $message")
+ def required(expression: Boolean, errorMessage: Any): Unit = {
+ if (!expression) {
+ throw new IllegalArgumentException(s"requirement failed: ${errorMessage.toString}")
}
}
+ def uuid(): String = UUID.randomUUID().toString.replaceAll("-", "")
+
@throws[IOException]
def checkJarFile(jar: URL): Unit = {
val jarFile: File = Try(new File(jar.toURI)) match {
@@ -135,4 +150,18 @@ object Utils {
result
}
+ def stringifyException(e: Throwable): String = {
+ if (e == null) "(null)" else {
+ try {
+ val stm = new StringWriter
+ val wrt = new PrintWriter(stm)
+ e.printStackTrace(wrt)
+ wrt.close()
+ stm.toString
+ } catch {
+ case _: Throwable => e.getClass.getName + " (error while printing stack trace)"
+ }
+ }
+ }
+
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/AlertException.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/AlertException.java
index 812ebed4e..9763f67c0 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/AlertException.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/AlertException.java
@@ -17,7 +17,7 @@
package org.apache.streampark.console.base.exception;
-import org.apache.streampark.common.util.ExceptionUtils;
+import org.apache.streampark.common.util.Utils;
public class AlertException extends ApiAlertException {
public AlertException(String message) {
@@ -25,7 +25,7 @@ public class AlertException extends ApiAlertException {
}
public AlertException(Throwable cause) {
- super(ExceptionUtils.stringifyException(cause));
+ super(Utils.stringifyException(cause));
}
public AlertException(String message, Throwable cause) {
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApiDetailException.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApiDetailException.java
index 5adbd8c72..6385f0167 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApiDetailException.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApiDetailException.java
@@ -17,7 +17,7 @@
package org.apache.streampark.console.base.exception;
-import org.apache.streampark.common.util.ExceptionUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.base.domain.ResponseCode;
/**
@@ -37,11 +37,11 @@ public class ApiDetailException extends AbstractApiException {
}
public ApiDetailException(Throwable cause) {
- super(ExceptionUtils.stringifyException(cause), ResponseCode.CODE_FAIL_DETAIL);
+ super(Utils.stringifyException(cause), ResponseCode.CODE_FAIL_DETAIL);
}
public ApiDetailException(String message, Throwable cause) {
- super(message + ExceptionUtils.stringifyException(cause), ResponseCode.CODE_FAIL_DETAIL);
+ super(message + Utils.stringifyException(cause), ResponseCode.CODE_FAIL_DETAIL);
}
@Override
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/interceptor/UploadFileTypeInterceptor.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/interceptor/UploadFileTypeInterceptor.java
index 32513fb47..69c96e0b3 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/interceptor/UploadFileTypeInterceptor.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/interceptor/UploadFileTypeInterceptor.java
@@ -17,8 +17,8 @@
package org.apache.streampark.console.base.interceptor;
-import org.apache.streampark.common.util.AssertUtils;
import org.apache.streampark.common.util.FileUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.base.exception.ApiAlertException;
import org.springframework.stereotype.Component;
@@ -43,7 +43,7 @@ public class UploadFileTypeInterceptor implements HandlerInterceptor {
Map<String, MultipartFile> files = multipartRequest.getFileMap();
for (String file : files.keySet()) {
MultipartFile multipartFile = multipartRequest.getFile(file);
- AssertUtils.state(multipartFile != null);
+ Utils.required(multipartFile != null);
boolean fileType = FileUtils.isJarFileType(multipartFile.getInputStream());
if (!fileType) {
throw new ApiAlertException("illegal file type, Only standard jar files supported");
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/CommonUtils.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/CommonUtils.java
index c6c52bc33..0efb46a12 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/CommonUtils.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/CommonUtils.java
@@ -17,7 +17,7 @@
package org.apache.streampark.console.base.util;
-import org.apache.streampark.common.util.AssertUtils;
+import org.apache.streampark.common.util.Utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cglib.beans.BeanMap;
@@ -451,7 +451,7 @@ public final class CommonUtils implements Serializable {
}
public static <T> T[] arrayRemoveElements(T[] array, T... elem) {
- AssertUtils.notNull(array);
+ Utils.required(array != null);
List<T> arrayList = new ArrayList<>(0);
Collections.addAll(arrayList, array);
if (isEmpty(elem)) {
@@ -464,7 +464,7 @@ public final class CommonUtils implements Serializable {
}
public static <T> T[] arrayRemoveIndex(T[] array, int... index) {
- AssertUtils.notNull(array);
+ Utils.notNull(array);
for (int j : index) {
if (j < 0 || j > array.length - 1) {
throw new IndexOutOfBoundsException("index error.@" + j);
@@ -481,7 +481,7 @@ public final class CommonUtils implements Serializable {
}
public static <T> T[] arrayInsertIndex(T[] array, int index, T t) {
- AssertUtils.notNull(array);
+ Utils.notNull(array);
List<T> arrayList = new ArrayList<T>(array.length + 1);
if (index == 0) {
arrayList.add(t);
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/ProjectController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/ProjectController.java
index 3af92bdc8..0f5818dbc 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/ProjectController.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/ProjectController.java
@@ -17,7 +17,7 @@
package org.apache.streampark.console.core.controller;
-import org.apache.streampark.common.util.AssertUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.base.domain.RestRequest;
import org.apache.streampark.console.base.domain.RestResponse;
import org.apache.streampark.console.core.annotation.AppUpdated;
@@ -50,7 +50,7 @@ public class ProjectController {
@PostMapping("create")
@RequiresPermissions("project:create")
public RestResponse create(Project project) {
- AssertUtils.checkArgument(project.getTeamId() != null, "The teamId cannot be null");
+ Utils.required(project.getTeamId() != null, "The teamId cannot be null");
return projectService.create(project);
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvInitializer.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvInitializer.java
index a547f431d..9327d6f70 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvInitializer.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvInitializer.java
@@ -24,8 +24,8 @@ import org.apache.streampark.common.conf.InternalOption;
import org.apache.streampark.common.conf.Workspace;
import org.apache.streampark.common.enums.StorageType;
import org.apache.streampark.common.fs.FsOperator;
-import org.apache.streampark.common.util.AssertUtils;
import org.apache.streampark.common.util.SystemPropertyUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.base.util.WebUtils;
import org.apache.streampark.console.core.entity.FlinkEnv;
import org.apache.streampark.console.core.service.SettingService;
@@ -98,7 +98,7 @@ public class EnvInitializer implements ApplicationRunner {
.forEach(
key -> {
InternalOption config = InternalConfigHolder.getConfig(key);
- AssertUtils.state(config != null);
+ Utils.required(config != null);
InternalConfigHolder.set(config, springEnv.getProperty(key, config.classType()));
});
@@ -182,7 +182,7 @@ public class EnvInitializer implements ApplicationRunner {
// 2. upload jar.
// 2.1) upload client jar
File client = WebUtils.getAppClientDir();
- AssertUtils.checkArgument(
+ Utils.required(
client.exists() && client.listFiles().length > 0,
client.getAbsolutePath().concat(" is not exists or empty directory "));
@@ -209,8 +209,7 @@ public class EnvInitializer implements ApplicationRunner {
WebUtils.getAppLibDir()
.listFiles(pathname -> pathname.getName().matches(PATTERN_FLINK_SHIMS_JAR.pattern()));
- AssertUtils.checkArgument(
- shims != null && shims.length > 0, "streampark-flink-shims jar not exist");
+ Utils.required(shims != null && shims.length > 0, "streampark-flink-shims jar not exist");
String appShims = workspace.APP_SHIMS();
fsOperator.delete(appShims);
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/AlertServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/AlertServiceImpl.java
index 0dbe07305..7d7beb456 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/AlertServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/AlertServiceImpl.java
@@ -17,7 +17,7 @@
package org.apache.streampark.console.core.service.alert.impl;
-import org.apache.streampark.common.util.AssertUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.base.exception.AlertException;
import org.apache.streampark.console.base.util.SpringContextUtils;
import org.apache.streampark.console.core.bean.AlertConfigWithParams;
@@ -84,7 +84,7 @@ public class AlertServiceImpl implements AlertService {
try {
Class<? extends AlertNotifyService> notifyServiceClass =
getAlertServiceImpl(alertType);
- AssertUtils.state(notifyServiceClass != null);
+ Utils.required(notifyServiceClass != null);
boolean alertRes =
SpringContextUtils.getBean(notifyServiceClass)
.doAlert(params, alertTemplate);
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/AppBuildPipeServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/AppBuildPipeServiceImpl.java
index 7d9fc974d..9d4134d72 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/AppBuildPipeServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/AppBuildPipeServiceImpl.java
@@ -23,10 +23,9 @@ import org.apache.streampark.common.enums.ApplicationType;
import org.apache.streampark.common.enums.DevelopmentMode;
import org.apache.streampark.common.enums.ExecutionMode;
import org.apache.streampark.common.fs.FsOperator;
-import org.apache.streampark.common.util.AssertUtils;
-import org.apache.streampark.common.util.ExceptionUtils;
import org.apache.streampark.common.util.FileUtils;
import org.apache.streampark.common.util.ThreadUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.base.util.WebUtils;
import org.apache.streampark.console.core.entity.AppBuildPipeline;
import org.apache.streampark.console.core.entity.Application;
@@ -146,7 +145,7 @@ public class AppBuildPipeServiceImpl
FlinkSql effectiveFlinkSql = flinkSqlService.getEffective(app.getId(), false);
if (app.isFlinkSqlJob()) {
FlinkSql flinkSql = newFlinkSql == null ? effectiveFlinkSql : newFlinkSql;
- AssertUtils.state(flinkSql != null);
+ Utils.required(flinkSql != null);
app.setDependency(flinkSql.getDependency());
}
@@ -210,7 +209,7 @@ public class AppBuildPipeServiceImpl
// copy jar to local upload dir
for (String jar : app.getDependencyObject().getJar()) {
File localJar = new File(WebUtils.getAppTempDir(), jar);
- AssertUtils.state(localJar.exists());
+ Utils.required(localJar.exists());
String localUploads = Workspace.local().APP_UPLOADS();
String uploadJar = localUploads.concat("/").concat(jar);
checkOrElseUploadJar(FsOperator.lfs(), localJar, uploadJar, localUploads);
@@ -271,7 +270,7 @@ public class AppBuildPipeServiceImpl
commonService.getUserId(),
app.getId(),
app.getJobName().concat(" launch failed"),
- ExceptionUtils.stringifyException(snapshot.error().exception()),
+ Utils.stringifyException(snapshot.error().exception()),
NoticeType.EXCEPTION);
messageService.push(message);
app.setLaunch(LaunchState.FAILED.get());
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationBackUpServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationBackUpServiceImpl.java
index 1cdb0dbb3..8902c3f64 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationBackUpServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationBackUpServiceImpl.java
@@ -18,8 +18,8 @@
package org.apache.streampark.console.core.service.impl;
import org.apache.streampark.common.fs.FsOperator;
-import org.apache.streampark.common.util.AssertUtils;
import org.apache.streampark.common.util.ThreadUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.base.domain.RestRequest;
import org.apache.streampark.console.base.exception.InternalException;
import org.apache.streampark.console.base.mybatis.pager.MybatisPager;
@@ -190,7 +190,7 @@ public class ApplicationBackUpServiceImpl
@Override
public void rollbackFlinkSql(Application application, FlinkSql sql) {
ApplicationBackUp backUp = getFlinkSqlBackup(application.getId(), sql.getId());
- AssertUtils.state(backUp != null);
+ Utils.required(backUp != null);
// rollback config and sql
effectiveService.saveOrUpdate(backUp.getAppId(), EffectiveType.CONFIG, backUp.getId());
effectiveService.saveOrUpdate(backUp.getAppId(), EffectiveType.FLINKSQL, backUp.getSqlId());
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationServiceImpl.java
index 00a0ffd7a..d51002325 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationServiceImpl.java
@@ -25,10 +25,8 @@ import org.apache.streampark.common.enums.ResolveOrder;
import org.apache.streampark.common.enums.StorageType;
import org.apache.streampark.common.fs.HdfsOperator;
import org.apache.streampark.common.fs.LfsOperator;
-import org.apache.streampark.common.util.AssertUtils;
import org.apache.streampark.common.util.CompletableFutureUtils;
import org.apache.streampark.common.util.DeflaterUtils;
-import org.apache.streampark.common.util.ExceptionUtils;
import org.apache.streampark.common.util.FlinkUtils;
import org.apache.streampark.common.util.HadoopUtils;
import org.apache.streampark.common.util.ThreadUtils;
@@ -339,7 +337,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
@Override
public void revoke(Application appParma) throws ApplicationException {
Application application = getById(appParma.getId());
- AssertUtils.state(
+ Utils.required(
application != null,
String.format("The application id=%s cannot be find in the database.", appParma.getId()));
@@ -434,7 +432,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
}
return true;
} catch (Exception e) {
- log.error(ExceptionUtils.stringifyException(e));
+ log.error(Utils.stringifyException(e));
throw new ApiDetailException(e);
}
}
@@ -580,9 +578,10 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
@Override
public String k8sStartLog(Long id, Integer offset, Integer limit) throws Exception {
Application application = getById(id);
- AssertUtils.state(application != null);
+ Utils.required(
+ application != null,
+ String.format("The application id=%s cannot be find in the database.", id));
if (ExecutionMode.isKubernetesMode(application.getExecutionModeEnum())) {
-
CompletableFuture<String> future =
CompletableFuture.supplyAsync(
() ->
@@ -692,7 +691,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
@Override
@Transactional(rollbackFor = {Exception.class})
public boolean create(Application appParam) {
- AssertUtils.checkArgument(appParam.getTeamId() != null, "The teamId cannot be null");
+ Utils.required(appParam.getTeamId() != null, "The teamId cannot be null");
appParam.setUserId(commonService.getUserId());
appParam.setState(FlinkAppState.ADDED.getValue());
appParam.setLaunch(LaunchState.NEED_LAUNCH.get());
@@ -715,7 +714,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
if (appParam.getConfig() != null) {
configService.create(appParam, true);
}
- AssertUtils.state(appParam.getId() != null);
+ Utils.required(appParam.getId() != null);
return true;
}
return false;
@@ -804,7 +803,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
configService.save(config);
configService.setLatestOrEffective(true, config.getId(), newApp.getId());
}
- AssertUtils.state(newApp.getId() != null);
+ Utils.required(newApp.getId() != null);
return newApp.getId();
}
return 0L;
@@ -938,7 +937,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
} else {
// get previous flink sql and decode
FlinkSql copySourceFlinkSql = flinkSqlService.getById(appParam.getSqlId());
- AssertUtils.state(copySourceFlinkSql != null);
+ Utils.required(copySourceFlinkSql != null);
copySourceFlinkSql.decode();
// get submit flink sql
@@ -1193,7 +1192,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
} else if (ExecutionMode.isYarnMode(application.getExecutionMode())) {
if (ExecutionMode.YARN_SESSION.equals(application.getExecutionModeEnum())) {
FlinkCluster cluster = flinkClusterService.getById(application.getFlinkClusterId());
- AssertUtils.state(
+ Utils.required(
cluster != null,
String.format(
"The yarn session clusterId=%s cannot be find, maybe the clusterId is wrong or "
@@ -1209,7 +1208,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
if (ExecutionMode.isRemoteMode(application.getExecutionModeEnum())) {
FlinkCluster cluster = flinkClusterService.getById(application.getFlinkClusterId());
- AssertUtils.state(
+ Utils.required(
cluster != null,
String.format(
"The clusterId=%s cannot be find, maybe the clusterId is wrong or "
@@ -1285,7 +1284,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
log.setAppId(application.getId());
log.setYarnAppId(application.getClusterId());
log.setOptionTime(new Date());
- String exception = ExceptionUtils.stringifyException(e);
+ String exception = Utils.stringifyException(e);
log.setException(exception);
log.setSuccess(false);
applicationLogService.save(log);
@@ -1348,7 +1347,9 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
@Override
public void starting(Application appParam) {
Application application = getById(appParam.getId());
- AssertUtils.state(application != null);
+ Utils.required(
+ application != null,
+ String.format("The application id=%s cannot be find in the database.", appParam.getId()));
application.setState(FlinkAppState.STARTING.getValue());
application.setOptionTime(new Date());
updateById(application);
@@ -1360,7 +1361,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
final Application application = getById(appParam.getId());
- AssertUtils.state(application != null);
+ Utils.required(application != null);
application.setAllowNonRestored(appParam.getAllowNonRestored());
FlinkEnv flinkEnv = flinkEnvService.getByIdOrDefault(application.getVersionId());
@@ -1391,7 +1392,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
ApplicationConfig applicationConfig = configService.getEffective(application.getId());
ExecutionMode executionMode = ExecutionMode.of(application.getExecutionMode());
- AssertUtils.state(executionMode != null);
+ Utils.required(executionMode != null, "executionMode cannot be null");
if (application.isCustomCodeJob()) {
if (application.isUploadJob()) {
appConf =
@@ -1439,7 +1440,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
}
} else if (application.isFlinkSqlJob()) {
FlinkSql flinkSql = flinkSqlService.getEffective(application.getId(), false);
- AssertUtils.state(flinkSql != null);
+ Utils.required(flinkSql != null);
// 1) dist_userJar
String sqlDistJar = commonService.getSqlClientJar(flinkEnv);
// 2) appConfig
@@ -1473,14 +1474,14 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
AppBuildPipeline buildPipeline = appBuildPipeService.getById(application.getId());
- AssertUtils.state(buildPipeline != null);
+ Utils.required(buildPipeline != null);
BuildResult buildResult = buildPipeline.getBuildResult();
if (ExecutionMode.YARN_APPLICATION.equals(executionMode)) {
buildResult = new ShadedBuildResponse(null, flinkUserJar, true);
} else {
if (ExecutionMode.isKubernetesApplicationMode(application.getExecutionMode())) {
- AssertUtils.state(buildResult != null);
+ Utils.required(buildResult != null);
DockerImageBuildResponse result = buildResult.as(DockerImageBuildResponse.class);
String ingressTemplates = application.getIngressTemplate();
String domainName = application.getDefaultModeIngress();
@@ -1584,7 +1585,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
if (e.getCause() instanceof CancellationException) {
updateToStopped(application);
} else {
- String exception = ExceptionUtils.stringifyException(e);
+ String exception = Utils.stringifyException(e);
applicationLog.setException(exception);
applicationLog.setSuccess(false);
applicationLogService.save(applicationLog);
@@ -1609,7 +1610,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
Map<String, Object> properties = application.getOptionMap();
if (ExecutionMode.isRemoteMode(application.getExecutionModeEnum())) {
FlinkCluster cluster = flinkClusterService.getById(application.getFlinkClusterId());
- AssertUtils.state(
+ Utils.required(
cluster != null,
String.format(
"The clusterId=%s cannot be find, maybe the clusterId is wrong or "
@@ -1626,7 +1627,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
}
if (ExecutionMode.YARN_SESSION.equals(application.getExecutionModeEnum())) {
FlinkCluster cluster = flinkClusterService.getById(application.getFlinkClusterId());
- AssertUtils.state(
+ Utils.required(
cluster != null,
String.format(
"The yarn session clusterId=%s cannot be find, maybe the clusterId is wrong or "
@@ -1718,7 +1719,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
// 3.1) At the remote mode, request the flink webui interface to get the savepoint path
if (ExecutionMode.isRemoteMode(application.getExecutionMode())) {
FlinkCluster cluster = flinkClusterService.getById(application.getFlinkClusterId());
- AssertUtils.state(
+ Utils.required(
cluster != null,
String.format(
"The clusterId=%s cannot be find, maybe the clusterId is wrong or "
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkSqlServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkSqlServiceImpl.java
index a35a585b2..ba0b3bd05 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkSqlServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkSqlServiceImpl.java
@@ -17,9 +17,8 @@
package org.apache.streampark.console.core.service.impl;
-import org.apache.streampark.common.util.AssertUtils;
import org.apache.streampark.common.util.DeflaterUtils;
-import org.apache.streampark.common.util.ExceptionUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.core.entity.Application;
import org.apache.streampark.console.core.entity.FlinkEnv;
import org.apache.streampark.console.core.entity.FlinkSql;
@@ -170,11 +169,11 @@ public class FlinkSqlServiceImpl extends ServiceImpl<FlinkSqlMapper, FlinkSql>
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void rollback(Application application) {
FlinkSql sql = getCandidate(application.getId(), CandidateType.HISTORY);
- AssertUtils.state(sql != null);
+ Utils.required(sql != null);
try {
// check and backup current job
FlinkSql effectiveSql = getEffective(application.getId(), false);
- AssertUtils.state(effectiveSql != null);
+ Utils.required(effectiveSql != null);
// rollback history sql
backUpService.rollbackFlinkSql(application, sql);
} catch (Exception e) {
@@ -199,8 +198,7 @@ public class FlinkSqlServiceImpl extends ServiceImpl<FlinkSqlMapper, FlinkSql>
}
return FlinkShimsProxy.getObject(this.getClass().getClassLoader(), result);
} catch (Throwable e) {
- log.error(
- "verifySql invocationTargetException: {}", ExceptionUtils.stringifyException(e));
+ log.error("verifySql invocationTargetException: {}", Utils.stringifyException(e));
}
return null;
});
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java
index 5dfa124d4..fd9112e0e 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java
@@ -20,9 +20,9 @@ package org.apache.streampark.console.core.service.impl;
import org.apache.streampark.common.conf.CommonConfig;
import org.apache.streampark.common.conf.InternalConfigHolder;
import org.apache.streampark.common.conf.Workspace;
-import org.apache.streampark.common.util.AssertUtils;
import org.apache.streampark.common.util.CompletableFutureUtils;
import org.apache.streampark.common.util.ThreadUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.base.domain.ResponseCode;
import org.apache.streampark.console.base.domain.RestRequest;
import org.apache.streampark.console.base.domain.RestResponse;
@@ -116,8 +116,8 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project>
public boolean update(Project projectParam) {
try {
Project project = getById(projectParam.getId());
- AssertUtils.state(project != null);
- AssertUtils.checkArgument(
+ Utils.required(project != null);
+ Utils.required(
project.getTeamId().equals(projectParam.getTeamId()), "TeamId cannot be changed.");
project.setName(projectParam.getName());
project.setUrl(projectParam.getUrl());
@@ -162,7 +162,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project>
@Transactional(rollbackFor = {Exception.class})
public boolean delete(Long id) {
Project project = getById(id);
- AssertUtils.state(project != null);
+ Utils.required(project != null);
LambdaQueryWrapper<Application> queryWrapper =
new LambdaQueryWrapper<Application>().eq(Application::getProjectId, id);
long count = applicationService.count(queryWrapper);
@@ -234,7 +234,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project>
@Override
public List<String> modules(Long id) {
Project project = getById(id);
- AssertUtils.state(project != null);
+ Utils.required(project != null);
BuildState buildState = BuildState.of(project.getBuildState());
if (BuildState.SUCCESSFUL.equals(buildState)) {
File appHome = project.getDistHome();
@@ -309,7 +309,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project>
}
List<Map<String, Object>> list = new ArrayList<>();
File[] files = unzipFile.listFiles(x -> "conf".equals(x.getName()));
- AssertUtils.state(files != null);
+ Utils.required(files != null);
for (File item : files) {
eachFile(item, list, true);
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SavePointServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SavePointServiceImpl.java
index 440019be3..2aebae099 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SavePointServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SavePointServiceImpl.java
@@ -17,7 +17,7 @@
package org.apache.streampark.console.core.service.impl;
-import org.apache.streampark.common.util.AssertUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.base.domain.Constant;
import org.apache.streampark.console.base.domain.RestRequest;
import org.apache.streampark.console.base.exception.InternalException;
@@ -67,7 +67,7 @@ public class SavePointServiceImpl extends ServiceImpl<SavePointMapper, SavePoint
private void expire(SavePoint entity) {
FlinkEnv flinkEnv = flinkEnvService.getByAppId(entity.getAppId());
- AssertUtils.state(flinkEnv != null);
+ Utils.required(flinkEnv != null);
int cpThreshold =
Integer.parseInt(
flinkEnv.convertFlinkYamlAsMap().getOrDefault("state.checkpoints.num-retained", "5"));
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SqlCompleteServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SqlCompleteServiceImpl.java
index 432f367bf..ddeeb22e4 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SqlCompleteServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SqlCompleteServiceImpl.java
@@ -17,7 +17,7 @@
package org.apache.streampark.console.core.service.impl;
-import org.apache.streampark.common.util.AssertUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.core.service.SqlCompleteService;
import com.google.common.collect.Sets;
@@ -185,7 +185,7 @@ public class SqlCompleteServiceImpl implements SqlCompleteService {
nowStep = nowStep.get(nowChar).getNext();
loc += 1;
}
- AssertUtils.state(preNode != null);
+ Utils.required(preNode != null);
preNode.setStop();
preNode.setCount(count);
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/task/FlinkRESTAPIWatcher.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/task/FlinkRESTAPIWatcher.java
index 123e9b2de..9edab9681 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/task/FlinkRESTAPIWatcher.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/task/FlinkRESTAPIWatcher.java
@@ -18,9 +18,9 @@
package org.apache.streampark.console.core.task;
import org.apache.streampark.common.enums.ExecutionMode;
-import org.apache.streampark.common.util.AssertUtils;
import org.apache.streampark.common.util.HttpClientUtils;
import org.apache.streampark.common.util.ThreadUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.common.util.YarnUtils;
import org.apache.streampark.console.base.util.JacksonUtils;
import org.apache.streampark.console.core.entity.Application;
@@ -207,7 +207,7 @@ public class FlinkRESTAPIWatcher {
final OptionState optionState = OPTIONING.get(key);
try {
// query status from flink rest api
- AssertUtils.state(application.getId() != null);
+ Utils.required(application.getId() != null);
getFromFlinkRestApi(application, stopFrom);
} catch (Exception flinkException) {
// query status from yarn rest api
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/UserController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/UserController.java
index d43cc3069..09b5cf1d0 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/UserController.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/UserController.java
@@ -20,6 +20,7 @@ package org.apache.streampark.console.system.controller;
import org.apache.streampark.console.base.domain.ResponseCode;
import org.apache.streampark.console.base.domain.RestRequest;
import org.apache.streampark.console.base.domain.RestResponse;
+import org.apache.streampark.console.base.exception.ApiAlertException;
import org.apache.streampark.console.base.util.ShaHashUtils;
import org.apache.streampark.console.core.enums.UserType;
import org.apache.streampark.console.core.service.CommonService;
@@ -172,9 +173,10 @@ public class UserController {
if (team == null) {
return RestResponse.fail("teamId is invalid", ResponseCode.CODE_FAIL_ALERT);
}
-
User user = commonService.getCurrentUser();
-
+ if (user == null) {
+ throw new ApiAlertException("current login user is null, set team failed");
+ }
// 1) set the latest team
userService.setLastTeam(teamId, user.getUserId());
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/MemberServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/MemberServiceImpl.java
index f7079beff..c4f015e3e 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/MemberServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/MemberServiceImpl.java
@@ -17,7 +17,7 @@
package org.apache.streampark.console.system.service.impl;
-import org.apache.streampark.common.util.AssertUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.base.domain.RestRequest;
import org.apache.streampark.console.base.exception.ApiAlertException;
import org.apache.streampark.console.system.entity.Member;
@@ -75,7 +75,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
@Override
public IPage<Member> findUsers(Member member, RestRequest request) {
- AssertUtils.isTrue(member.getTeamId() != null, "The team id is required.");
+ Utils.required(member.getTeamId() != null, "The team id is required.");
Page<Member> page = new Page<>();
page.setCurrent(request.getPageNum());
page.setSize(request.getPageSize());
@@ -102,7 +102,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
}
private Member findByUserId(Long teamId, Long userId) {
- AssertUtils.isTrue(teamId != null, "The team id is required.");
+ Utils.required(teamId != null, "The team id is required.");
LambdaQueryWrapper<Member> queryWrapper =
new LambdaQueryWrapper<Member>()
.eq(Member::getTeamId, teamId)
@@ -137,7 +137,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
() ->
new ApiAlertException(
String.format("The teamId [%s] not found", member.getTeamId())));
- AssertUtils.isTrue(
+ Utils.required(
findByUserId(member.getTeamId(), user.getUserId()) == null,
String.format(
"The user [%s] has been added the team [%s], please don't add it again.",
@@ -170,10 +170,8 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
() ->
new ApiAlertException(
String.format("The member [id=%s] not found", member.getId())));
- AssertUtils.isTrue(
- oldMember.getTeamId().equals(member.getTeamId()), "Team id cannot be changed.");
- AssertUtils.isTrue(
- oldMember.getUserId().equals(member.getUserId()), "User id cannot be changed.");
+ Utils.required(oldMember.getTeamId().equals(member.getTeamId()), "Team id cannot be changed.");
+ Utils.required(oldMember.getUserId().equals(member.getUserId()), "User id cannot be changed.");
Optional.ofNullable(roleService.getById(member.getRoleId()))
.orElseThrow(
() ->
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/RoleServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/RoleServiceImpl.java
index c8a97cc4c..1ca9dbdb2 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/RoleServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/RoleServiceImpl.java
@@ -17,7 +17,7 @@
package org.apache.streampark.console.system.service.impl;
-import org.apache.streampark.common.util.AssertUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.base.domain.Constant;
import org.apache.streampark.console.base.domain.RestRequest;
import org.apache.streampark.console.system.entity.Role;
@@ -86,7 +86,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
() ->
new IllegalArgumentException(String.format("Role id [%s] not found", roleId)));
List<Long> userIdsByRoleId = memberService.findUserIdsByRoleId(roleId);
- AssertUtils.isTrue(
+ Utils.required(
userIdsByRoleId == null || userIdsByRoleId.isEmpty(),
String.format(
"There are some users are bound to role %s , please unbind it first.",
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/TeamServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/TeamServiceImpl.java
index 0d712fd4a..a786de301 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/TeamServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/TeamServiceImpl.java
@@ -17,7 +17,7 @@
package org.apache.streampark.console.system.service.impl;
-import org.apache.streampark.common.util.AssertUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.base.domain.RestRequest;
import org.apache.streampark.console.base.exception.ApiAlertException;
import org.apache.streampark.console.core.enums.UserType;
@@ -129,7 +129,7 @@ public class TeamServiceImpl extends ServiceImpl<TeamMapper, Team> implements Te
() ->
new IllegalArgumentException(
String.format("Team id [id=%s] not found", team.getId())));
- AssertUtils.isTrue(
+ Utils.required(
oldTeam.getTeamName().equals(team.getTeamName()), "Team name cannot be changed.");
oldTeam.setDescription(team.getDescription());
oldTeam.setModifyTime(new Date());
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java
index f58291712..99ba05aad 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java
@@ -17,7 +17,7 @@
package org.apache.streampark.console.system.service.impl;
-import org.apache.streampark.common.util.AssertUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.console.base.domain.RestRequest;
import org.apache.streampark.console.base.exception.ApiAlertException;
import org.apache.streampark.console.base.util.ShaHashUtils;
@@ -74,7 +74,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
page.setSize(request.getPageSize());
IPage<User> resPage = this.baseMapper.findUserDetail(page, user);
- AssertUtils.state(resPage != null);
+ Utils.required(resPage != null);
if (resPage.getTotal() == 0) {
resPage.setRecords(Collections.emptyList());
}
@@ -189,7 +189,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
@Override
public void setLastTeam(Long teamId, Long userId) {
User user = getById(userId);
- AssertUtils.checkArgument(user != null);
+ Utils.required(user != null);
user.setLastTeamId(teamId);
this.baseMapper.updateById(user);
}
@@ -197,7 +197,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
@Override
public void clearLastTeam(Long userId, Long teamId) {
User user = getById(userId);
- AssertUtils.checkArgument(user != null);
+ Utils.required(user != null);
if (!teamId.equals(user.getLastTeamId())) {
return;
}
@@ -238,7 +238,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
*/
@Override
public Map<String, Object> generateFrontendUserInfo(User user, Long teamId, JWTToken token) {
- AssertUtils.checkNotNull(user);
Map<String, Object> userInfo = new HashMap<>(8);
// 1) token & expire
diff --git a/streampark-flink/streampark-flink-client/streampark-flink-client-core/src/main/scala/org/apache/streampark/flink/client/trait/YarnSubmitTrait.scala b/streampark-flink/streampark-flink-client/streampark-flink-client-core/src/main/scala/org/apache/streampark/flink/client/trait/YarnSubmitTrait.scala
index da34f30eb..1aaa5f491 100644
--- a/streampark-flink/streampark-flink-client/streampark-flink-client-core/src/main/scala/org/apache/streampark/flink/client/trait/YarnSubmitTrait.scala
+++ b/streampark-flink/streampark-flink-client/streampark-flink-client-core/src/main/scala/org/apache/streampark/flink/client/trait/YarnSubmitTrait.scala
@@ -19,9 +19,7 @@ package org.apache.streampark.flink.client.`trait`
import java.lang.{Boolean => JavaBool}
import java.lang.reflect.Method
-
import scala.util.Try
-
import org.apache.flink.client.deployment.{ClusterDescriptor, ClusterSpecification, DefaultClusterClientServiceLoader}
import org.apache.flink.client.program.ClusterClientProvider
import org.apache.flink.configuration.Configuration
@@ -30,8 +28,7 @@ import org.apache.flink.util.FlinkException
import org.apache.flink.yarn.{YarnClusterClientFactory, YarnClusterDescriptor}
import org.apache.flink.yarn.configuration.YarnConfigOptions
import org.apache.hadoop.yarn.api.records.ApplicationId
-
-import org.apache.streampark.common.util.ExceptionUtils
+import org.apache.streampark.common.util.Utils
import org.apache.streampark.flink.client.bean._
/**
@@ -57,7 +54,7 @@ trait YarnSubmitTrait extends FlinkSubmitTrait {
CancelResponse(savepointDir)
}.recover {
case e => throw new FlinkException(
- s"[StreamPark] Triggering a savepoint for the job ${cancelRequest.jobId} failed. detail: ${ExceptionUtils.stringifyException(e)}");
+ s"[StreamPark] Triggering a savepoint for the job ${cancelRequest.jobId} failed. detail: ${Utils.stringifyException(e)}");
}.get
}
diff --git a/streampark-flink/streampark-flink-connector/streampark-flink-connector-hbase/src/main/scala/org/apache/streampark/flink/connector/hbase/source/HBaseJavaSource.java b/streampark-flink/streampark-flink-connector/streampark-flink-connector-hbase/src/main/scala/org/apache/streampark/flink/connector/hbase/source/HBaseJavaSource.java
index 95c9942b0..4d8b59314 100644
--- a/streampark-flink/streampark-flink-connector/streampark-flink-connector-hbase/src/main/scala/org/apache/streampark/flink/connector/hbase/source/HBaseJavaSource.java
+++ b/streampark-flink/streampark-flink-connector/streampark-flink-connector-hbase/src/main/scala/org/apache/streampark/flink/connector/hbase/source/HBaseJavaSource.java
@@ -41,8 +41,8 @@ public class HBaseJavaSource<T> {
HBaseResultFunction<T> resultFunction,
RunningFunction runningFunc) {
- Utils.require(queryFunction != null, "queryFunction must not be null");
- Utils.require(resultFunction != null, "resultFunction must not be null");
+ Utils.required(queryFunction != null, "queryFunction must not be null");
+ Utils.required(resultFunction != null, "resultFunction must not be null");
HBaseSourceFunction<T> sourceFunction = new HBaseSourceFunction<>(
property,
queryFunction,
diff --git a/streampark-flink/streampark-flink-connector/streampark-flink-connector-jdbc/src/main/scala/org/apache/streampark/flink/connector/jdbc/sink/JdbcJavaSink.java b/streampark-flink/streampark-flink-connector/streampark-flink-connector-jdbc/src/main/scala/org/apache/streampark/flink/connector/jdbc/sink/JdbcJavaSink.java
index 9b7928307..1bbb0cc8a 100644
--- a/streampark-flink/streampark-flink-connector/streampark-flink-connector-jdbc/src/main/scala/org/apache/streampark/flink/connector/jdbc/sink/JdbcJavaSink.java
+++ b/streampark-flink/streampark-flink-connector/streampark-flink-connector-jdbc/src/main/scala/org/apache/streampark/flink/connector/jdbc/sink/JdbcJavaSink.java
@@ -17,8 +17,8 @@
package org.apache.streampark.flink.connector.jdbc.sink;
-import org.apache.streampark.common.util.AssertUtils;
import org.apache.streampark.common.util.ConfigUtils;
+import org.apache.streampark.common.util.Utils;
import org.apache.streampark.flink.connector.function.TransformFunction;
import org.apache.streampark.flink.connector.jdbc.internal.JdbcSinkFunction;
import org.apache.streampark.flink.core.scala.StreamingContext;
@@ -55,7 +55,7 @@ public class JdbcJavaSink<T> {
}
public DataStreamSink<T> sink(DataStream<T> dataStream) {
- AssertUtils.notNull(sqlFunc);
+ Utils.required(sqlFunc != null, "transformFunction can not be null");
this.jdbc = this.jdbc == null ? ConfigUtils.getJdbcConf(context.parameter().toMap(), alias) : this.jdbc;
JdbcSinkFunction<T> sinkFun = new JdbcSinkFunction<>(this.jdbc, this.sqlFunc);
return dataStream.addSink(sinkFun);
diff --git a/streampark-flink/streampark-flink-connector/streampark-flink-connector-jdbc/src/main/scala/org/apache/streampark/flink/connector/jdbc/source/JdbcJavaSource.java b/streampark-flink/streampark-flink-connector/streampark-flink-connector-jdbc/src/main/scala/org/apache/streampark/flink/connector/jdbc/source/JdbcJavaSource.java
index 58f4f05a9..42df8de68 100644
--- a/streampark-flink/streampark-flink-connector/streampark-flink-connector-jdbc/src/main/scala/org/apache/streampark/flink/connector/jdbc/source/JdbcJavaSource.java
+++ b/streampark-flink/streampark-flink-connector/streampark-flink-connector-jdbc/src/main/scala/org/apache/streampark/flink/connector/jdbc/source/JdbcJavaSource.java
@@ -53,8 +53,8 @@ public class JdbcJavaSource<T> {
SQLResultFunction<T> resultFunction,
RunningFunction runningFunc) {
- Utils.require(queryFunction != null, "queryFunction must not be null");
- Utils.require(resultFunction != null, "resultFunction must not be null");
+ Utils.required(queryFunction != null, "queryFunction must not be null");
+ Utils.required(resultFunction != null, "resultFunction must not be null");
this.jdbc = this.jdbc == null ? ConfigUtils.getJdbcConf(context.parameter().toMap(), alias) : this.jdbc;
JdbcSourceFunction<T> sourceFunction = new JdbcSourceFunction<>(jdbc, queryFunction, resultFunction, runningFunc, null);
return context.getJavaEnv().addSource(sourceFunction);
diff --git a/streampark-flink/streampark-flink-connector/streampark-flink-connector-mongo/src/main/scala/org/apache/streampark/flink/connector/mongo/source/MongoJavaSource.java b/streampark-flink/streampark-flink-connector/streampark-flink-connector-mongo/src/main/scala/org/apache/streampark/flink/connector/mongo/source/MongoJavaSource.java
index 2b1dd0d13..25e63d743 100644
--- a/streampark-flink/streampark-flink-connector/streampark-flink-connector-mongo/src/main/scala/org/apache/streampark/flink/connector/mongo/source/MongoJavaSource.java
+++ b/streampark-flink/streampark-flink-connector/streampark-flink-connector-mongo/src/main/scala/org/apache/streampark/flink/connector/mongo/source/MongoJavaSource.java
@@ -42,9 +42,9 @@ public class MongoJavaSource<T> {
MongoResultFunction<T> resultFunction,
RunningFunction runningFunc) {
- Utils.require(collectionName != null, "collectionName must not be null");
- Utils.require(queryFunction != null, "queryFunction must not be null");
- Utils.require(resultFunction != null, "resultFunction must not be null");
+ Utils.required(collectionName != null, "collectionName must not be null");
+ Utils.required(queryFunction != null, "queryFunction must not be null");
+ Utils.required(resultFunction != null, "resultFunction must not be null");
MongoSourceFunction<T> sourceFunction = new MongoSourceFunction<>(collectionName, property, queryFunction, resultFunction, runningFunc, null);
return context.getJavaEnv().addSource(sourceFunction);
diff --git a/streampark-flink/streampark-flink-shims/streampark-flink-shims-base/src/main/scala/org/apache/streampark/flink/core/FlinkSqlValidator.scala b/streampark-flink/streampark-flink-shims/streampark-flink-shims-base/src/main/scala/org/apache/streampark/flink/core/FlinkSqlValidator.scala
index 9ca27f473..575461614 100644
--- a/streampark-flink/streampark-flink-shims/streampark-flink-shims-base/src/main/scala/org/apache/streampark/flink/core/FlinkSqlValidator.scala
+++ b/streampark-flink/streampark-flink-shims/streampark-flink-shims-base/src/main/scala/org/apache/streampark/flink/core/FlinkSqlValidator.scala
@@ -17,7 +17,6 @@
package org.apache.streampark.flink.core
import scala.util.{Failure, Try}
-
import org.apache.calcite.config.Lex
import org.apache.calcite.sql.parser.SqlParser
import org.apache.calcite.sql.parser.SqlParser.Config
@@ -28,9 +27,8 @@ import org.apache.flink.table.api.{SqlDialect, TableConfig}
import org.apache.flink.table.api.SqlDialect.{DEFAULT, HIVE}
import org.apache.flink.table.api.config.TableConfigOptions
import org.apache.flink.table.planner.delegation.FlinkSqlParserFactories
-
import org.apache.streampark.common.enums.FlinkSqlValidationFailedType
-import org.apache.streampark.common.util.{ExceptionUtils, Logger}
+import org.apache.streampark.common.util.{Logger, Utils}
import org.apache.streampark.flink.core.SqlCommand._
object FlinkSqlValidator extends Logger {
@@ -95,7 +93,7 @@ object FlinkSqlValidator extends Logger {
}
} match {
case Failure(e) =>
- val exception = ExceptionUtils.stringifyException(e)
+ val exception = Utils.stringifyException(e)
val causedBy = exception.drop(exception.indexOf("Caused by:"))
val cleanUpError = exception.replaceAll("[\r\n]", "")
if (SYNTAX_ERROR_REGEXP.findAllMatchIn(cleanUpError).nonEmpty) {