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 2022/12/30 10:08:18 UTC
[incubator-streampark] branch dev updated: [Improve] added spotless-plugin and checkstyle improvement (#2213)
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 39cc162be [Improve] added spotless-plugin and checkstyle improvement (#2213)
39cc162be is described below
commit 39cc162be89fd861a88d3a385ee9e8db7b9564d8
Author: benjobs <be...@apache.org>
AuthorDate: Fri Dec 30 18:08:12 2022 +0800
[Improve] added spotless-plugin and checkstyle improvement (#2213)
* [Improve] added spotless-plugin and checkstyle improvement
---
.github/workflows/maven.yml | 6 +-
pom.xml | 161 +-
.../streampark/common/conf/ConfigConst.scala | 8 +-
.../streampark/common/conf/ConfigOption.scala | 14 +-
.../common/conf/InternalConfigHolder.scala | 21 +-
.../streampark/common/conf/InternalOption.scala | 7 +-
.../streampark/common/conf/K8sFlinkConfig.scala | 1 -
.../apache/streampark/common/conf/Workspace.scala | 7 +-
.../streampark/common/domain/FlinkVersion.scala | 28 +-
.../streampark/common/enums/RestartStrategy.scala | 4 +-
.../apache/streampark/common/fs/HdfsOperator.scala | 2 -
.../apache/streampark/common/fs/LfsOperator.scala | 15 +-
.../streampark/common/util/AssertUtils.scala | 1 -
.../streampark/common/util/CURLBuilder.scala | 4 +-
.../streampark/common/util/ClassLoaderUtils.scala | 4 +-
.../streampark/common/util/CommandUtils.scala | 8 +-
.../common/util/CompletableFutureUtils.scala | 68 +-
.../streampark/common/util/ConfigUtils.scala | 15 +-
.../apache/streampark/common/util/DateUtils.scala | 8 +-
.../streampark/common/util/DependencyUtils.scala | 124 +-
.../streampark/common/util/ExceptionUtils.scala | 26 +-
.../apache/streampark/common/util/FileUtils.scala | 8 +-
.../streampark/common/util/FlinkClientUtils.scala | 10 +-
.../apache/streampark/common/util/FlinkUtils.scala | 8 +-
.../streampark/common/util/HBaseClient.scala | 11 +-
.../streampark/common/util/HadoopConfigUtils.scala | 22 +-
.../streampark/common/util/HadoopUtils.scala | 57 +-
.../apache/streampark/common/util/HdfsUtils.scala | 12 +-
.../apache/streampark/common/util/HostsUtils.scala | 4 +-
.../streampark/common/util/HttpClientUtils.scala | 24 +-
.../apache/streampark/common/util/JdbcUtils.scala | 33 +-
.../apache/streampark/common/util/JsonUtils.scala | 7 +-
.../org/apache/streampark/common/util/Logger.scala | 3 +-
.../streampark/common/util/MongoConfig.scala | 11 +-
.../streampark/common/util/PropertiesUtils.scala | 13 +-
.../streampark/common/util/RedisClient.scala | 25 +-
.../streampark/common/util/RedisEndpoint.scala | 96 +-
.../apache/streampark/common/util/RedisUtils.scala | 289 +-
.../streampark/common/util/ReflectUtils.scala | 16 +-
.../streampark/common/util/SqlConvertUtils.scala | 45 +-
.../common/util/SystemPropertyUtils.scala | 13 +-
.../streampark/common/util/ThreadUtils.scala | 6 +-
.../org/apache/streampark/common/util/Utils.scala | 12 +-
.../apache/streampark/common/util/YarnUtils.scala | 67 +-
.../streampark/common/util/ZooKeeperUtils.scala | 13 +-
.../streampark/common/fs/LfsOperatorTest.scala | 29 +-
.../org/apache/streampark/common/fs/package.scala | 8 +-
.../console/StreamParkConsoleBootstrap.java | 31 +-
.../base/config/AlertRestTemplateConfig.java | 18 +-
.../base/config/AsyncExecutorPoolConfig.java | 22 +-
.../console/base/config/MybatisConfig.java | 98 +-
.../console/base/config/P6spySqlFormatConfig.java | 34 +-
.../console/base/config/SwaggerConfig.java | 131 +-
.../console/base/config/WebMvcConfig.java | 73 +-
.../console/base/config/WebSocketConfig.java | 8 +-
.../console/base/domain/ApiDocConstant.java | 3 +-
.../streampark/console/base/domain/Constant.java | 27 +-
.../console/base/domain/ResponseCode.java | 10 +-
.../console/base/domain/RestRequest.java | 10 +-
.../console/base/domain/RestResponse.java | 74 +-
.../console/base/domain/router/RouterMeta.java | 15 +-
.../console/base/domain/router/RouterTree.java | 77 +-
.../console/base/domain/router/VueRouter.java | 36 +-
.../streampark/console/base/enums/FileType.java | 30 +-
.../base/exception/AbstractApiException.java | 35 +-
.../console/base/exception/AlertException.java | 18 +-
.../console/base/exception/ApiAlertException.java | 21 +-
.../console/base/exception/ApiDetailException.java | 28 +-
.../base/exception/ApplicationException.java | 13 +-
.../base/exception/IllegalFileTypeException.java | 12 +-
.../console/base/exception/InternalException.java | 16 +-
.../base/handler/GlobalExceptionHandler.java | 117 +-
.../interceptor/FileHeaderCheckInterceptor.java | 100 +-
.../interceptor/PostgreSQLPrepareInterceptor.java | 41 +-
.../interceptor/PostgreSQLQueryInterceptor.java | 85 +-
.../console/base/mybatis/pager/MybatisPager.java | 55 +-
.../console/base/properties/ShiroProperties.java | 9 +-
.../streampark/console/base/util/CommonUtils.java | 1100 ++++----
.../streampark/console/base/util/EncryptUtils.java | 138 +-
.../streampark/console/base/util/FileUtils.java | 91 +-
.../console/base/util/FreemarkerUtils.java | 63 +-
.../streampark/console/base/util/GZipUtils.java | 130 +-
.../streampark/console/base/util/GitUtils.java | 129 +-
.../streampark/console/base/util/JacksonUtils.java | 54 +-
.../streampark/console/base/util/MoreFutures.java | 144 +-
.../streampark/console/base/util/ObjectUtils.java | 1782 ++++++-------
.../streampark/console/base/util/ShaHashUtils.java | 71 +-
.../console/base/util/SpringContextUtils.java | 46 +-
.../console/base/util/VueRouterUtils.java | 169 +-
.../streampark/console/base/util/WebUtils.java | 171 +-
.../console/core/annotation/ApiAccess.java | 3 +-
.../console/core/annotation/RefreshCache.java | 3 +-
.../core/aspect/StreamParkConsoleAspect.java | 52 +-
.../console/core/bean/AlertConfigWithParams.java | 97 +-
.../console/core/bean/AlertDingTalkParams.java | 29 +-
.../console/core/bean/AlertEmailParams.java | 6 +-
.../console/core/bean/AlertHttpCallbackParams.java | 18 +-
.../console/core/bean/AlertLarkParams.java | 21 +-
.../console/core/bean/AlertLarkRobotResponse.java | 21 +-
.../console/core/bean/AlertTemplate.java | 124 +-
.../console/core/bean/AlertWeComParams.java | 7 +-
.../core/bean/AppBuildDockerResolvedDetail.java | 186 +-
.../streampark/console/core/bean/AppControl.java | 19 +-
.../apache/streampark/console/core/bean/Note.java | 58 +-
.../console/core/bean/ResponseResult.java | 6 +-
.../console/core/bean/RobotResponse.java | 10 +-
.../streampark/console/core/bean/SenderEmail.java | 13 +-
.../console/core/controller/AlertController.java | 190 +-
.../ApplicationBuildPipelineController.java | 147 +-
.../core/controller/ApplicationController.java | 636 +++--
.../controller/ApplicationHistoryController.java | 110 +-
.../console/core/controller/ConfigController.java | 67 +-
.../core/controller/FlinkClusterController.java | 97 +-
.../core/controller/FlinkEnvController.java | 88 +-
.../controller/FlinkPodTemplateController.java | 99 +-
.../core/controller/FlinkSqlController.java | 99 +-
.../console/core/controller/IndexController.java | 8 +-
.../console/core/controller/MetricsController.java | 28 +-
.../core/controller/NoteBookController.java | 11 +-
.../console/core/controller/ProjectController.java | 184 +-
.../core/controller/SavePointController.java | 42 +-
.../console/core/controller/SettingController.java | 67 +-
.../core/controller/TutorialController.java | 13 +-
.../core/controller/VariableController.java | 148 +-
.../console/core/entity/AlertConfig.java | 142 +-
.../console/core/entity/AppBuildPipeline.java | 486 ++--
.../console/core/entity/Application.java | 1204 ++++-----
.../console/core/entity/ApplicationBackUp.java | 88 +-
.../console/core/entity/ApplicationConfig.java | 134 +-
.../console/core/entity/ApplicationLog.java | 40 +-
.../streampark/console/core/entity/Effective.java | 45 +-
.../console/core/entity/FlinkCluster.java | 241 +-
.../streampark/console/core/entity/FlinkEnv.java | 136 +-
.../streampark/console/core/entity/FlinkSql.java | 129 +-
.../streampark/console/core/entity/Message.java | 45 +-
.../streampark/console/core/entity/Project.java | 332 ++-
.../streampark/console/core/entity/SavePoint.java | 26 +-
.../streampark/console/core/entity/Setting.java | 25 +-
.../streampark/console/core/entity/Tutorial.java | 13 +-
.../streampark/console/core/entity/Variable.java | 52 +-
.../console/core/enums/AccessTokenState.java | 33 +-
.../streampark/console/core/enums/AlertType.java | 94 +-
.../console/core/enums/AppExistsState.java | 59 +-
.../streampark/console/core/enums/BuildState.java | 64 +-
.../console/core/enums/CandidateType.java | 50 +-
.../streampark/console/core/enums/ChangedType.java | 91 +-
.../console/core/enums/CheckPointStatus.java | 48 +-
.../console/core/enums/CheckPointType.java | 44 +-
.../console/core/enums/ConfigFileType.java | 43 +-
.../console/core/enums/EffectiveType.java | 26 +-
.../console/core/enums/FlinkAppState.java | 255 +-
.../console/core/enums/GitAuthorizedError.java | 54 +-
.../streampark/console/core/enums/GitProtocol.java | 25 +-
.../streampark/console/core/enums/LaunchState.java | 68 +-
.../streampark/console/core/enums/NoticeType.java | 33 +-
.../streampark/console/core/enums/OptionState.java | 54 +-
.../console/core/enums/ResourceFrom.java | 32 +-
.../streampark/console/core/enums/StopFrom.java | 12 +-
.../streampark/console/core/enums/UserType.java | 37 +-
.../console/core/mapper/AlertConfigMapper.java | 2 +-
.../core/mapper/ApplicationBackUpMapper.java | 4 +-
.../mapper/ApplicationBuildPipelineMapper.java | 4 +-
.../core/mapper/ApplicationConfigMapper.java | 8 +-
.../console/core/mapper/ApplicationLogMapper.java | 4 +-
.../console/core/mapper/ApplicationMapper.java | 35 +-
.../console/core/mapper/EffectiveMapper.java | 4 +-
.../console/core/mapper/FlinkClusterMapper.java | 5 +-
.../console/core/mapper/FlinkEnvMapper.java | 4 +-
.../console/core/mapper/FlinkSqlMapper.java | 6 +-
.../console/core/mapper/MessageMapper.java | 3 +-
.../console/core/mapper/ProjectMapper.java | 9 +-
.../console/core/mapper/SavePointMapper.java | 4 +-
.../console/core/mapper/SettingMapper.java | 4 +-
.../console/core/mapper/TutorialMapper.java | 4 +-
.../console/core/mapper/VariableMapper.java | 7 +-
.../console/core/metrics/flink/CheckPoints.java | 77 +-
.../console/core/metrics/flink/JobsOverview.java | 58 +-
.../console/core/metrics/flink/JvmProfiler.java | 30 +-
.../console/core/metrics/flink/Overview.java | 34 +-
.../console/core/metrics/yarn/AppInfo.java | 66 +-
.../console/core/runner/EnvInitializer.java | 377 ++-
.../console/core/service/AppBuildPipeService.java | 60 +-
.../core/service/ApplicationBackUpService.java | 16 +-
.../core/service/ApplicationConfigService.java | 22 +-
.../core/service/ApplicationLogService.java | 5 +-
.../console/core/service/ApplicationService.java | 84 +-
.../console/core/service/CommonService.java | 7 +-
.../console/core/service/EffectiveService.java | 8 +-
.../console/core/service/FlinkClusterService.java | 16 +-
.../console/core/service/FlinkEnvService.java | 104 +-
.../console/core/service/FlinkSqlService.java | 24 +-
.../console/core/service/LogClientService.java | 68 +-
.../console/core/service/LoggerService.java | 3 +-
.../console/core/service/MessageService.java | 4 +-
.../console/core/service/ProjectService.java | 27 +-
.../console/core/service/SavePointService.java | 11 +-
.../console/core/service/SettingService.java | 60 +-
.../console/core/service/SqlCompleteService.java | 2 +-
.../console/core/service/TutorialService.java | 2 +-
.../console/core/service/VariableService.java | 67 +-
.../core/service/alert/AlertConfigService.java | 6 +-
.../core/service/alert/AlertNotifyService.java | 3 +-
.../console/core/service/alert/AlertService.java | 6 +-
.../service/alert/impl/AlertConfigServiceImpl.java | 64 +-
.../core/service/alert/impl/AlertServiceImpl.java | 154 +-
.../alert/impl/DingTalkAlertNotifyServiceImpl.java | 258 +-
.../alert/impl/EmailAlertNotifyServiceImpl.java | 88 +-
.../impl/HttpCallbackAlertNotifyServiceImpl.java | 128 +-
.../alert/impl/LarkAlertNotifyServiceImpl.java | 197 +-
.../alert/impl/WeComAlertNotifyServiceImpl.java | 151 +-
.../core/service/impl/AppBuildPipeServiceImpl.java | 682 ++---
.../service/impl/ApplicationBackUpServiceImpl.java | 344 +--
.../service/impl/ApplicationConfigServiceImpl.java | 343 ++-
.../service/impl/ApplicationLogServiceImpl.java | 26 +-
.../core/service/impl/ApplicationServiceImpl.java | 2762 ++++++++++----------
.../core/service/impl/CommonServiceImpl.java | 75 +-
.../core/service/impl/EffectiveServiceImpl.java | 71 +-
.../core/service/impl/FlinkClusterServiceImpl.java | 481 ++--
.../core/service/impl/FlinkEnvServiceImpl.java | 128 +-
.../core/service/impl/FlinkSqlServiceImpl.java | 282 +-
.../core/service/impl/LoggerServiceImpl.java | 50 +-
.../core/service/impl/MessageServiceImpl.java | 26 +-
.../core/service/impl/ProjectServiceImpl.java | 496 ++--
.../core/service/impl/SavePointServiceImpl.java | 194 +-
.../core/service/impl/SettingServiceImpl.java | 256 +-
.../core/service/impl/SqlCompleteServiceImpl.java | 566 ++--
.../core/service/impl/TutorialServiceImpl.java | 15 +-
.../core/service/impl/VariableServiceImpl.java | 318 +--
.../console/core/task/AbstractLogFileTask.java | 146 +-
.../console/core/task/CheckpointProcessor.java | 157 +-
.../console/core/task/FlinkTrackingTask.java | 1451 +++++-----
.../core/task/K8sFlinkChangeEventListener.java | 268 +-
.../core/task/K8sFlinkTrackMonitorWrapper.java | 179 +-
.../console/core/task/PackerResourceGCTask.java | 15 +-
.../console/core/task/ProjectBuildTask.java | 354 +--
.../console/core/websocket/WebSocketEndpoint.java | 94 +-
.../console/system/authentication/JWTFilter.java | 123 +-
.../console/system/authentication/JWTToken.java | 42 +-
.../console/system/authentication/JWTUtil.java | 153 +-
.../console/system/authentication/ShiroConfig.java | 138 +-
.../console/system/authentication/ShiroRealm.java | 110 +-
.../system/controller/AccessTokenController.java | 165 +-
.../system/controller/MemberController.java | 70 +-
.../console/system/controller/MenuController.java | 72 +-
.../system/controller/PassportController.java | 118 +-
.../console/system/controller/RoleController.java | 78 +-
.../console/system/controller/TeamController.java | 60 +-
.../console/system/controller/UserController.java | 275 +-
.../console/system/entity/AccessToken.java | 55 +-
.../streampark/console/system/entity/Member.java | 28 +-
.../streampark/console/system/entity/Menu.java | 48 +-
.../streampark/console/system/entity/Role.java | 32 +-
.../streampark/console/system/entity/RoleMenu.java | 10 +-
.../streampark/console/system/entity/SysLog.java | 26 +-
.../streampark/console/system/entity/Team.java | 25 +-
.../streampark/console/system/entity/User.java | 91 +-
.../console/system/mapper/AccessTokenMapper.java | 9 +-
.../console/system/mapper/MemberMapper.java | 35 +-
.../console/system/mapper/MenuMapper.java | 19 +-
.../console/system/mapper/RoleMapper.java | 2 +-
.../console/system/mapper/RoleMenuMapper.java | 3 +-
.../console/system/mapper/TeamMapper.java | 5 +-
.../console/system/mapper/UserMapper.java | 11 +-
.../console/system/runner/StartedUpRunner.java | 13 +-
.../system/security/AuthenticationType.java | 24 +-
.../console/system/security/Authenticator.java | 21 +-
.../system/security/impl/AuthenticatorImpl.java | 72 +-
.../system/security/impl/ldap/LdapService.java | 168 +-
.../impl/ldap/LdapUserNotExistActionType.java | 22 +-
.../console/system/service/AccessTokenService.java | 14 +-
.../console/system/service/MemberService.java | 21 +-
.../console/system/service/MenuService.java | 38 +-
.../console/system/service/RoleMenuServie.java | 6 +-
.../console/system/service/RoleService.java | 10 +-
.../console/system/service/TeamService.java | 13 +-
.../console/system/service/UserService.java | 193 +-
.../service/impl/AccessTokenServiceImpl.java | 139 +-
.../system/service/impl/MemberServiceImpl.java | 236 +-
.../system/service/impl/MenuServiceImpl.java | 234 +-
.../system/service/impl/RoleMenuServiceImpl.java | 45 +-
.../system/service/impl/RoleServiceImpl.java | 136 +-
.../system/service/impl/TeamServiceImpl.java | 162 +-
.../system/service/impl/UserServiceImpl.java | 375 ++-
.../benmanes/caffeine/cache/RefreshCacheTest.java | 35 +-
.../util/concurrent/CompletableFutureTest.java | 182 +-
.../src/test/java/java/util/regex/RegexTest.java | 154 +-
.../org/apache/commons/mail/SendEmailTest.java | 201 +-
.../console/base/util/FileUtilsTest.java | 135 +-
.../console/base/util/ShaHashUtilsTest.java | 17 +-
.../console/core/entity/DependencyTest.java | 116 +-
.../streampark/console/core/entity/GitTest.java | 39 +-
.../console/core/enums/AlertTypeTest.java | 20 +-
.../core/service/ApplicationServiceTest.java | 115 +-
.../console/core/service/VariableServiceTest.java | 97 +-
.../core/service/alert/AlertServiceTest.java | 166 +-
.../console/system/authentication/JWTTest.java | 28 +-
.../flink/connector/conf/ThresholdConf.scala | 7 +-
.../connector/conf/ThresholdConfigOption.scala | 31 +-
.../flink/connector/failover/FailoverChecker.scala | 5 +-
.../flink/connector/failover/FailoverWriter.scala | 29 +-
.../flink/connector/failover/SinkBuffer.scala | 12 +-
.../flink/connector/failover/SinkRequest.scala | 11 +-
.../clickhouse/conf/ClickHouseHttpConfig.scala | 9 +-
.../clickhouse/conf/ClickHouseJdbcConfig.scala | 2 -
.../conf/ClickHouseSinkConfigOption.scala | 55 +-
.../internal/AsyncClickHouseSinkFunction.scala | 24 +-
.../internal/ClickHouseSinkFunction.scala | 42 +-
.../clickhouse/internal/ClickHouseSinkWriter.scala | 18 +-
.../clickhouse/internal/ClickHouseWriterTask.scala | 60 +-
.../sink/AsyncClickHouseOutputFormat.scala | 15 +-
.../clickhouse/sink/ClickHouseOutputFormat.scala | 13 +-
.../connector/clickhouse/sink/ClickHouseSink.scala | 37 +-
.../connector/doris/bean/DorisSinkBufferEntry.java | 208 +-
.../doris/bean/DorisSinkRowDataWithMeta.java | 48 +-
.../doris/bean/LoadStatusFailedException.java | 46 +-
.../flink/connector/doris/bean/RespContent.java | 509 ++--
.../doris/internal/DorisSinkFunction.java | 157 +-
.../connector/doris/internal/DorisSinkWriter.java | 501 ++--
.../doris/internal/DorisStreamLoader.java | 398 +--
.../flink/connector/doris/sink/DorisSink.java | 52 +-
.../connector/doris/util/DorisDelimiterParser.java | 80 +-
.../connector/doris/conf/DorisConfig.scala | 7 +-
.../doris/conf/DorisSinkConfigOption.scala | 59 +-
.../elasticsearch5/conf/ESSinkConfigOption.scala | 27 +-
.../elasticsearch5/internal/ESSinkFunction.scala | 13 +-
.../connector/elasticsearch5/sink/ES5Sink.scala | 89 +-
.../elasticsearch5/util/ElasticsearchUtils.scala | 1 -
.../bean/RestClientFactoryImpl.scala | 14 +-
.../connector/elasticsearch6/conf/ES6Config.scala | 5 +-
.../elasticsearch6/conf/ES6SinkConfigOption.scala | 73 +-
.../elasticsearch6/internal/ESSinkFunction.scala | 12 +-
.../connector/elasticsearch6/sink/ES6Sink.scala | 100 +-
.../bean/RestClientFactoryImpl.scala | 12 +-
.../connector/elasticsearch7/conf/ES7Config.scala | 5 +-
.../elasticsearch7/conf/ES7SinkConfigOption.scala | 75 +-
.../elasticsearch7/internal/ESSinkFunction.scala | 10 +-
.../connector/elasticsearch7/sink/ES7Sink.scala | 95 +-
.../elasticsearch7/util/ElasticsearchUtils.scala | 2 +-
.../hbase/internal/HBaseSinkFunction.scala | 60 +-
.../hbase/internal/HBaseSourceFunction.scala | 43 +-
.../connector/hbase/request/HBaseRequest.scala | 49 +-
.../connector/hbase/sink/HBaseOutputFormat.scala | 20 +-
.../flink/connector/hbase/sink/HBaseSink.scala | 43 +-
.../flink/connector/hbase/source/HBaseSource.scala | 26 +-
.../connector/http/conf/HttpConfigOption.scala | 4 -
.../connector/http/function/HttpSinkFunction.scala | 19 +-
.../connector/http/internal/HttpSinkWriter.scala | 33 +-
.../connector/http/internal/HttpWriterTask.scala | 95 +-
.../flink/connector/http/sink/HttpSink.scala | 43 +-
.../flink/connector/influx/bean/InfluxEntity.scala | 19 +-
.../connector/influx/function/InfluxFunction.scala | 19 +-
.../connector/influx/sink/InfluxOutputFormat.scala | 9 +-
.../flink/connector/influx/sink/InfluxSink.scala | 34 +-
.../flink/connector/jdbc/bean/Transaction.scala | 10 +-
.../jdbc/internal/Jdbc2PCSinkFunction.scala | 20 +-
.../jdbc/internal/JdbcASyncFunction.scala | 20 +-
.../connector/jdbc/internal/JdbcSinkFunction.scala | 13 +-
.../jdbc/internal/JdbcSourceFunction.scala | 41 +-
.../flink/connector/jdbc/request/JdbcRequest.scala | 36 +-
.../flink/connector/jdbc/sink/JdbcSink.scala | 47 +-
.../flink/connector/jdbc/source/JdbcSource.scala | 26 +-
.../kafka/bean/KafkaEqualityPartitioner.scala | 12 +-
.../flink/connector/kafka/bean/KafkaRecord.scala | 13 +-
.../flink/connector/kafka/sink/KafkaSink.scala | 54 +-
.../flink/connector/kafka/source/KafkaSource.scala | 108 +-
.../mongo/internal/MongoSourceFunction.scala | 47 +-
.../flink/connector/mongo/source/MongoSource.scala | 28 +-
.../connector/redis/bean/RedisContainer.scala | 66 +-
.../flink/connector/redis/bean/RedisMapper.scala | 30 +-
.../connector/redis/bean/RedisTransaction.scala | 10 +-
.../flink/connector/redis/conf/RedisConfig.scala | 7 +-
.../redis/conf/RedisSinkConfigOption.scala | 22 +-
.../redis/internal/Redis2PCSinkFunction.scala | 10 +-
.../redis/internal/RedisSinkFunction.scala | 15 +-
.../flink/connector/redis/sink/RedisSink.scala | 54 +-
.../flink/core/scala/DataStreamExt.scala | 16 +-
.../flink/core/scala/FlinkStreamTable.scala | 19 +-
.../flink/core/scala/FlinkStreaming.scala | 25 +-
.../streampark/flink/core/scala/FlinkTable.scala | 11 +-
.../resources/CompKubernetesDeployment.java | 6 +-
.../resources/CompatibleKubernetesWatcher.java | 15 +-
.../resources/SilentWatchCallbackHandler.java | 29 +-
.../flink/kubernetes/ChangeEventBus.scala | 10 +-
.../kubernetes/DefaultK8sFlinkTrackMonitor.scala | 10 +-
.../flink/kubernetes/FlinkTrackController.scala | 12 +-
.../flink/kubernetes/IngressController.scala | 51 +-
.../flink/kubernetes/K8sFlinkTrackMonitor.scala | 8 +-
.../K8sFlinkTrackMonitorLazyStartAop.scala | 4 -
.../flink/kubernetes/KubernetesRetriever.scala | 28 +-
.../flink/kubernetes/PodTemplateParser.scala | 33 +-
.../flink/kubernetes/PodTemplateTool.scala | 9 +-
.../streampark/flink/kubernetes/TrackConfig.scala | 19 +-
.../flink/kubernetes/event/BuildInEvent.scala | 4 +-
.../event/FlinkJobCheckpointChangeEvent.scala | 1 -
.../kubernetes/event/FlinkJobStateEvent.scala | 1 -
.../event/FlinkJobStatusChangeEvent.scala | 1 -
.../helper/KubernetesDeploymentHelper.scala | 14 +-
.../helper/TrackMonitorDebugHelper.scala | 70 +-
.../flink/kubernetes/model/CheckpointCV.scala | 7 +-
.../flink/kubernetes/model/ClusterKey.scala | 5 +-
.../flink/kubernetes/model/FlinkMetricCV.scala | 41 +-
.../flink/kubernetes/model/JobStatusCV.scala | 20 +-
.../kubernetes/model/K8sDeploymentEventCV.scala | 1 -
.../flink/kubernetes/model/K8sPodTemplates.scala | 9 +-
.../flink/kubernetes/model/TrackId.scala | 23 +-
.../watcher/FlinkCheckpointWatcher.scala | 64 +-
.../kubernetes/watcher/FlinkJobStatusWatcher.scala | 130 +-
.../kubernetes/watcher/FlinkK8sEventWatcher.scala | 18 +-
.../kubernetes/watcher/FlinkMetricsWatcher.scala | 76 +-
.../flink/kubernetes/watcher/FlinkWatcher.scala | 3 +-
.../flink/kubernetes/FlinkRestJsonTest.scala | 18 +-
.../flink/kubernetes/PodTemplateParserTest.scala | 109 +-
.../api/command/HackBuildImageResultCallback.java | 35 +-
.../api/command/HackPullImageResultCallback.java | 21 +-
.../api/command/HackPushImageResultCallback.java | 21 +-
.../api/listener/BuildImageCallbackListener.java | 13 +-
.../api/listener/PullImageCallbackListener.java | 7 +-
.../api/listener/PushImageCallbackListener.java | 7 +-
.../github/dockerjava/core/HackDockerClient.java | 66 +-
.../dockerjava/core/command/HackBuildImageCmd.java | 30 +-
.../dockerjava/core/command/HackPullImageCmd.java | 18 +-
.../dockerjava/core/command/HackPushImageCmd.java | 18 +-
.../flink/packer/pipeline/PipelineStatus.java | 52 +-
.../flink/packer/pipeline/PipelineStepStatus.java | 55 +-
.../flink/packer/pipeline/PipelineType.java | 204 +-
.../streampark/flink/packer/PackerResourceGC.scala | 10 +-
.../flink/packer/docker/DockerConf.scala | 15 +-
.../flink/packer/docker/DockerRetriever.scala | 7 +-
.../packer/docker/FlinkDockerfileTemplate.scala | 6 +-
.../docker/FlinkDockerfileTemplateTrait.scala | 9 +-
.../docker/FlinkHadoopDockerfileTemplate.scala | 31 +-
.../streampark/flink/packer/docker/package.scala | 5 +-
.../streampark/flink/packer/maven/Artifact.scala | 4 +-
.../flink/packer/maven/DependencyInfo.scala | 7 +-
.../streampark/flink/packer/maven/MavenTool.scala | 49 +-
.../flink/packer/pipeline/BuildPipeline.scala | 21 +-
.../flink/packer/pipeline/BuildRequest.scala | 102 +-
.../flink/packer/pipeline/BuildResponse.scala | 29 +-
.../packer/pipeline/DockerProgressWatcher.scala | 1 -
.../packer/pipeline/DockerResolveProgress.scala | 12 +-
.../packer/pipeline/DockerResolveSnapshot.scala | 15 +-
.../flink/packer/pipeline/PipeError.scala | 10 +-
.../flink/packer/pipeline/PipeSnapshot.scala | 23 +-
.../flink/packer/pipeline/PipeWatcher.scala | 12 +-
.../impl/FlinkK8sApplicationBuildPipeline.scala | 62 +-
.../impl/FlinkK8sSessionBuildPipeline.scala | 26 +-
.../pipeline/impl/FlinkRemoteBuildPipeline.scala | 6 +-
.../impl/FlinkYarnApplicationBuildPipeline.scala | 14 +-
.../streampark/flink/packer/DockerClientTest.scala | 7 +-
.../flink/packer/FlinkDockerfileTemplateSpec.scala | 5 +-
.../flink/packer/MavenArtifactSpec.scala | 10 +-
.../streampark/flink/packer/MavenToolSpec.scala | 19 +-
.../apache/streampark/flink/packer/package.scala | 7 +-
.../flink/proxy/ChildFirstClassLoader.scala | 36 +-
.../flink/proxy/ClassLoaderObjectInputStream.scala | 3 +-
.../streampark/flink/proxy/FlinkShimsProxy.scala | 98 +-
.../flink/core/StreamEnvConfigFunction.java | 16 +-
.../flink/core/TableEnvConfigFunction.java | 16 +-
.../streampark/flink/core/EnhancerImplicit.scala | 6 +-
.../streampark/flink/core/FlinkClientTrait.scala | 5 +-
.../streampark/flink/core/FlinkSqlExecutor.scala | 30 +-
.../streampark/flink/core/FlinkSqlValidator.scala | 19 +-
.../flink/core/FlinkStreamTableTrait.scala | 91 +-
.../flink/core/FlinkStreamingInitializer.scala | 30 +-
.../flink/core/FlinkTableInitializer.scala | 34 +-
.../streampark/flink/core/FlinkTableTrait.scala | 26 +-
.../streampark/flink/core/SqlCommandParser.scala | 312 +--
.../flink/core/conf/FlinkConfiguration.scala | 4 +-
.../flink/core/conf/FlinkRunOption.scala | 120 +-
.../streampark/flink/core/conf/ParameterCli.scala | 12 +-
.../java/org/apache/streampark/RegExpTest.java | 113 +-
.../flink/core/test/FlinkSqlExecuteFunSuite.scala | 7 +-
.../core/test/FlinkSqlValidationFunSuite.scala | 4 +-
.../streampark/flink/core/FlinkClusterClient.scala | 4 +-
.../streampark/flink/core/StreamTableContext.scala | 9 +-
.../streampark/flink/core/TableContext.scala | 11 +-
.../apache/streampark/flink/core/TableExt.scala | 2 +-
.../streampark/flink/core/FlinkClusterClient.scala | 4 +-
.../streampark/flink/core/StreamTableContext.scala | 11 +-
.../streampark/flink/core/TableContext.scala | 13 +-
.../apache/streampark/flink/core/TableExt.scala | 3 +-
.../streampark/flink/core/FlinkClusterClient.scala | 4 +-
.../streampark/flink/core/StreamTableContext.scala | 11 +-
.../streampark/flink/core/TableContext.scala | 10 +-
.../apache/streampark/flink/core/TableExt.scala | 3 +-
.../streampark/flink/core/FlinkClusterClient.scala | 4 +-
.../streampark/flink/core/StreamTableContext.scala | 8 +-
.../streampark/flink/core/TableContext.scala | 6 +-
.../apache/streampark/flink/core/TableExt.scala | 3 +-
.../streampark/flink/core/FlinkClusterClient.scala | 4 +-
.../streampark/flink/core/StreamTableContext.scala | 9 +-
.../streampark/flink/core/TableContext.scala | 5 +-
.../apache/streampark/flink/core/TableExt.scala | 2 +-
.../apache/streampark/flink/cli/SqlClient.scala | 10 +-
.../streampark/flink/submit/FlinkSubmitter.scala | 113 +-
.../flink/submit/bean/CancelRequest.scala | 25 +-
.../flink/submit/bean/DeployRequest.scala | 40 +-
.../flink/submit/bean/ShutDownRequest.scala | 14 +-
.../flink/submit/bean/SubmitRequest.scala | 91 +-
.../flink/submit/bean/SubmitResponse.scala | 5 +-
.../impl/KubernetesNativeApplicationSubmit.scala | 14 +-
.../impl/KubernetesNativeSessionSubmit.scala | 53 +-
.../streampark/flink/submit/impl/LocalSubmit.scala | 14 +-
.../flink/submit/impl/RemoteSubmit.scala | 25 +-
.../flink/submit/impl/YarnApplicationSubmit.scala | 38 +-
.../flink/submit/impl/YarnPerJobSubmit.scala | 21 +-
.../flink/submit/impl/YarnSessionSubmit.scala | 53 +-
.../submit/tool/FlinkSessionSubmitHelper.scala | 38 +-
.../flink/submit/trait/FlinkSubmitTrait.scala | 83 +-
.../submit/trait/KubernetesNativeSubmitTrait.scala | 41 +-
.../flink/submit/trait/YarnSubmitTrait.scala | 40 +-
.../flink/submit/test/ParameterTestCase.scala | 11 +-
.../flink/submit/test/YarnPerJobTestCase.scala | 58 +-
.../org/apache/streampark/flink/udf/UDF.scala | 4 +-
.../streampark/spark/connector/sink/ShowSink.scala | 3 +-
.../streampark/spark/connector/sink/Sink.scala | 16 +-
.../streampark/spark/connector/source/Source.scala | 14 +-
.../connector/kafka/offset/DefaultOffset.scala | 8 +-
.../spark/connector/kafka/offset/HBaseOffset.scala | 35 +-
.../spark/connector/kafka/offset/KafkaClient.scala | 42 +-
.../spark/connector/kafka/offset/MySQLOffset.scala | 33 +-
.../spark/connector/kafka/offset/Offset.scala | 18 +-
.../spark/connector/kafka/offset/RedisOffset.scala | 10 +-
.../spark/connector/kafka/sink/KafkaSink.scala | 15 +-
.../spark/connector/kafka/source/KafkaSource.scala | 25 +-
.../kafka/writer/DStreamKafkaWriter.scala | 26 +-
.../connector/kafka/writer/IterKafkaWriter.scala | 26 +-
.../spark/connector/kafka/writer/KafkaWriter.scala | 22 +-
.../connector/kafka/writer/RDDKafkaWriter.scala | 23 +-
.../connector/kafka/writer/SimpleKafkaWriter.scala | 27 +-
.../org/apache/streampark/spark/core/Spark.scala | 32 +-
.../apache/streampark/spark/core/SparkBatch.scala | 9 +-
.../streampark/spark/core/SparkStreaming.scala | 8 +-
.../serializable/MultipleAvroOutputsFormat.scala | 8 +-
.../spark/core/serializable/MultipleOutputer.scala | 34 +-
.../core/serializable/MultipleOutputsFormat.scala | 36 +-
.../serializable/MultipleTextOutputsFormat.scala | 3 +-
.../serializable/SerializationExtensions.scala | 61 +-
.../spark/core/util/SQLContextUtil.scala | 10 +-
.../apache/streampark/storage/StorageService.java | 7 +-
.../streampark/storage/StorageServiceConfig.java | 3 +-
.../apache/streampark/storage/oss/OssConfig.java | 10 +-
.../streampark/storage/oss/OssStorageService.java | 93 +-
.../storage/oss/OssStorageServiceTest.java | 23 +-
tools/checkstyle/.scalafmt.conf | 44 +
tools/checkstyle/checkstyle.xml | 496 ----
546 files changed, 19811 insertions(+), 20371 deletions(-)
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 663170ede..03677adf6 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -58,11 +58,11 @@ jobs:
with:
submodules: true
- name: Check codestyle for scala 2.11
- run: ./mvnw -B -q -nsu -Pscala-2.11 clean checkstyle:check
+ run: ./mvnw -B -q -nsu -Pscala-2.11 clean spotless:check
- name: Check codestyle for scala 2.12
- run: ./mvnw -B -q -nsu -Pscala-2.12 clean checkstyle:check
+ run: ./mvnw -B -q -nsu -Pscala-2.12 clean spotless:check
- name: Check codestyle for console
- run: ./mvnw -B -q -nsu -Pconsole clean checkstyle:check
+ run: ./mvnw -B -q -nsu -Pconsole clean spotless:check
dead-link:
if: github.repository == 'apache/incubator-streampark'
name: Dead links
diff --git a/pom.xml b/pom.xml
index bc882981c..324b0f223 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,8 +26,8 @@
<groupId>org.apache.streampark</groupId>
<artifactId>streampark</artifactId>
- <packaging>pom</packaging>
<version>2.0.0</version>
+ <packaging>pom</packaging>
<name>StreamPark Project Parent POM</name>
<url>https://streampark.apache.org/</url>
@@ -90,6 +90,7 @@
<scala.xml.version>1.3.0</scala.xml.version>
<scalatest.version>3.2.9</scalatest.version>
<scala.binary.flink.version>_${scala.binary.version}</scala.binary.flink.version>
+ <spotless.scala.scalafmt.version>3.6.1</spotless.scala.scalafmt.version>
<flink.version>1.14.0</flink.version>
<flink.shaded.version>1.8.1</flink.shaded.version>
@@ -122,7 +123,6 @@
<commons-lang3.version>3.8.1</commons-lang3.version>
<enumeratum.version>1.6.1</enumeratum.version>
- <maven-checkstyle-plugin.version>3.2.0</maven-checkstyle-plugin.version>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
<maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
<scala-maven-plugin.version>4.7.1</scala-maven-plugin.version>
@@ -130,10 +130,10 @@
<maven-deploy-plugin.version>3.0.0-M1</maven-deploy-plugin.version>
<maven-javadoc-plugin.version>2.9.1</maven-javadoc-plugin.version>
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
+ <maven-spotless-plugin.version>2.27.2</maven-spotless-plugin.version>
+ <maven-scalastyle-plugin.version>1.0.0</maven-scalastyle-plugin.version>
<build-helper-maven-plugin.version>3.3.0</build-helper-maven-plugin.version>
- <checkstyle.fails.on.error>true</checkstyle.fails.on.error>
<scalastyle.fails.on.error>true</scalastyle.fails.on.error>
- <scalastyle-maven-plugin.version>1.0.0</scalastyle-maven-plugin.version>
<streampark.shaded.package>org.apache.streampark.shaded</streampark.shaded.package>
<flink.table.uber.artifact.id>flink-table-uber_${scala.binary.version}</flink.table.uber.artifact.id>
<httpclient.version>4.5.13</httpclient.version>
@@ -320,8 +320,8 @@
<version>${hadoop.version}</version>
<exclusions>
<exclusion>
- <artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
@@ -340,8 +340,8 @@
<artifactId>commons-cli</artifactId>
</exclusion>
<exclusion>
- <artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
@@ -372,8 +372,8 @@
<artifactId>commons-cli</artifactId>
</exclusion>
<exclusion>
- <artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
@@ -388,8 +388,8 @@
<artifactId>*</artifactId>
</exclusion>
<exclusion>
- <artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
@@ -404,8 +404,8 @@
<artifactId>commons-cli</artifactId>
</exclusion>
<exclusion>
- <artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
@@ -420,16 +420,16 @@
<artifactId>*</artifactId>
</exclusion>
<exclusion>
- <artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
- <artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
@@ -440,8 +440,8 @@
<version>${hadoop.version}</version>
<exclusions>
<exclusion>
- <artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
@@ -452,8 +452,8 @@
<artifactId>*</artifactId>
</exclusion>
<exclusion>
- <artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
@@ -472,8 +472,8 @@
<artifactId>commons-cli</artifactId>
</exclusion>
<exclusion>
- <artifactId>slf4j-log4j12</artifactId>
<groupId>*</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
@@ -698,10 +698,10 @@
<executions>
<execution>
<id>add-source</id>
- <phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
+ <phase>generate-sources</phase>
<configuration>
<sources>
<source>${basedir}/src/main/java</source>
@@ -713,36 +713,21 @@
</plugin>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <version>${maven-checkstyle-plugin.version}</version>
+ <groupId>org.scalastyle</groupId>
+ <artifactId>scalastyle-maven-plugin</artifactId>
+ <version>${maven-scalastyle-plugin.version}</version>
<configuration>
+ <verbose>false</verbose>
+ <failOnViolation>${scalastyle.fails.on.error}</failOnViolation>
+ <includeTestSourceDirectory>true</includeTestSourceDirectory>
+ <failOnWarning>false</failOnWarning>
+ <sourceDirectory>${basedir}/src/main/scala</sourceDirectory>
+ <testSourceDirectory>${basedir}/src/test/scala</testSourceDirectory>
<!--suppress UnresolvedMavenProperty -->
- <configLocation>${maven.multiModuleProjectDirectory}/tools/checkstyle/checkstyle.xml</configLocation>
+ <configLocation>${maven.multiModuleProjectDirectory}/tools/checkstyle/scalastyle-config.xml</configLocation>
+ <outputFile>${project.build.directory}/target/scalastyle-output.xml</outputFile>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
- <consoleOutput>true</consoleOutput>
- <includeTestSourceDirectory>false</includeTestSourceDirectory>
- <failOnViolation>${checkstyle.fails.on.error}</failOnViolation>
- <sourceDirectories>
- <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
- <sourceDirectory>${project.build.testSourceDirectory}</sourceDirectory>
- </sourceDirectories>
- <resourceIncludes>
- **/*.properties,
- **/*.sh,
- **/*.bat,
- **/*.yml,
- **/*.yaml,
- **/*.xml,
- **/*.dict
- </resourceIncludes>
- <resourceExcludes>
- **/.asf.yaml,
- **/.github/**
- </resourceExcludes>
- <excludes>
- </excludes>
</configuration>
<dependencies>
<dependency>
@@ -754,42 +739,50 @@
<executions>
<execution>
<id>validate</id>
- <phase>process-sources</phase>
<goals>
<goal>check</goal>
</goals>
+ <phase>process-sources</phase>
</execution>
</executions>
</plugin>
<plugin>
- <groupId>org.scalastyle</groupId>
- <artifactId>scalastyle-maven-plugin</artifactId>
- <version>${scalastyle-maven-plugin.version}</version>
+ <groupId>com.diffplug.spotless</groupId>
+ <artifactId>spotless-maven-plugin</artifactId>
+ <version>${maven-spotless-plugin.version}</version>
<configuration>
- <verbose>false</verbose>
- <failOnViolation>${scalastyle.fails.on.error}</failOnViolation>
- <includeTestSourceDirectory>false</includeTestSourceDirectory>
- <failOnWarning>false</failOnWarning>
- <sourceDirectory>${basedir}/src/main/scala</sourceDirectory>
- <testSourceDirectory>${basedir}/src/test/scala</testSourceDirectory>
- <!--suppress UnresolvedMavenProperty -->
- <configLocation>${maven.multiModuleProjectDirectory}/tools/checkstyle/scalastyle-config.xml</configLocation>
- <outputFile>${project.build.directory}/target/scalastyle-output.xml</outputFile>
- <inputEncoding>UTF-8</inputEncoding>
- <outputEncoding>UTF-8</outputEncoding>
+ <java>
+ <includes>
+ <include>src/main/java/**/*.java</include>
+ <include>src/test/java/**/*.java</include>
+ </includes>
+ <googleJavaFormat>
+ <version>1.7</version>
+ <style>GOOGLE</style>
+ </googleJavaFormat>
+ <importOrder>
+ <order>org.apache.streampark,org.apache.streampark.shaded,,javax,java,scala,\#</order>
+ </importOrder>
+ <removeUnusedImports />
+ </java>
+ <scala>
+ <includes>
+ <include>src/main/scala/**/*.scala</include>
+ <include>src/test/scala/**/*.scala</include>
+ </includes>
+ <scalafmt>
+ <version>${spotless.scala.scalafmt.version}</version>
+ <scalaMajorVersion>2.12</scalaMajorVersion>
+ <!--suppress UnresolvedMavenProperty -->
+ <file>${maven.multiModuleProjectDirectory}/tools/checkstyle/.scalafmt.conf</file>
+ </scalafmt>
+ </scala>
</configuration>
- <dependencies>
- <dependency>
- <groupId>com.puppycrawl.tools</groupId>
- <artifactId>checkstyle</artifactId>
- <version>9.3</version>
- </dependency>
- </dependencies>
<executions>
<execution>
- <id>validate</id>
- <phase>process-sources</phase>
+ <id>spotless-check</id>
+ <phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
@@ -828,18 +821,18 @@
<executions>
<execution>
<id>install-scala</id>
- <phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
+ <phase>process-resources</phase>
</execution>
<execution>
<id>test-compile-scala</id>
- <phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
+ <phase>test-compile</phase>
</execution>
</executions>
</plugin>
@@ -891,10 +884,10 @@
<executions>
<execution>
<id>sign-release-artifacts</id>
- <phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
+ <phase>verify</phase>
</execution>
</executions>
</plugin>
@@ -911,14 +904,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- </execution>
- </executions>
<configuration>
<shadedArtifactId>true</shadedArtifactId>
<createDependencyReducedPom>true</createDependencyReducedPom>
@@ -937,6 +922,14 @@
</includes>
</artifactSet>
</configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <phase>package</phase>
+ </execution>
+ </executions>
</plugin>
<plugin>
@@ -950,13 +943,13 @@
</plugin>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
+ <groupId>org.scalastyle</groupId>
+ <artifactId>scalastyle-maven-plugin</artifactId>
</plugin>
<plugin>
- <groupId>org.scalastyle</groupId>
- <artifactId>scalastyle-maven-plugin</artifactId>
+ <groupId>com.diffplug.spotless</groupId>
+ <artifactId>spotless-maven-plugin</artifactId>
</plugin>
</plugins>
@@ -980,7 +973,7 @@
<properties>
<streampark.flink.shims.version>1.15</streampark.flink.shims.version>
<flink.version>1.15.0</flink.version>
- <scala.binary.flink.version/>
+ <scala.binary.flink.version />
<flink.table.uber.artifact.id>flink-table-api-java-uber</flink.table.uber.artifact.id>
</properties>
</profile>
@@ -995,13 +988,13 @@
<profile>
<id>scala-2.12</id>
+ <modules>
+ <module>streampark-spark</module>
+ </modules>
<properties>
<scala.version>2.12.8</scala.version>
<scala.binary.version>2.12</scala.binary.version>
</properties>
- <modules>
- <module>streampark-spark</module>
- </modules>
</profile>
<profile>
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/conf/ConfigConst.scala b/streampark-common/src/main/scala/org/apache/streampark/common/conf/ConfigConst.scala
index a10d777b5..1c6773a2e 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/conf/ConfigConst.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/conf/ConfigConst.scala
@@ -22,13 +22,11 @@ object ConfigConst {
/**
* common const
- *
*/
val DEFAULT_DATAMASK_STRING = "********"
/**
- *
* about parameter...
*/
@@ -83,7 +81,7 @@ object ConfigConst {
val KEY_JAVA_SECURITY_KRB5_CONF = "java.security.krb5.conf"
- //spark
+ // spark
val KEY_SPARK_USER_ARGS = "spark.user.args"
@@ -157,7 +155,6 @@ object ConfigConst {
val KEY_KAFKA_START_FROM_TIMESTAMP = "timestamp"
-
val KEY_ALIAS = "alias"
/**
@@ -234,6 +231,3 @@ object ConfigConst {
}
}
-
-
-
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/conf/ConfigOption.scala b/streampark-common/src/main/scala/org/apache/streampark/common/conf/ConfigOption.scala
index 8e04f02a6..33602d903 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/conf/ConfigOption.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/conf/ConfigOption.scala
@@ -17,11 +17,10 @@
package org.apache.streampark.common.conf
import java.util.Properties
-import scala.util.{Failure, Success, Try}
+import scala.util.{Failure, Success, Try}
/**
- *
* @param key key of configuration that consistent with the spring config.
* @param defaultValue default value of configuration that <b>should not be null</b>.
* @param classType the class type of value. <b>please use java class type</b>.
@@ -29,13 +28,10 @@ import scala.util.{Failure, Success, Try}
* @param description description of configuration.
* @param handle Processing function of special parameters
*/
-case class ConfigOption[T](key: String,
- defaultValue: T = null,
- required: Boolean,
- classType: Class[_],
- description: String = "",
- handle: String => T = null
- )(implicit prefix: String = "", prop: Properties) {
+case class ConfigOption[T](key: String, defaultValue: T = null, required: Boolean, classType: Class[_], description: String = "", handle: String => T = null)(
+ implicit
+ prefix: String = "",
+ prop: Properties) {
private[this] lazy val fullKey = if (prefix != null && !prefix.isEmpty) s"$prefix.$key" else key
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/conf/InternalConfigHolder.scala b/streampark-common/src/main/scala/org/apache/streampark/common/conf/InternalConfigHolder.scala
index 6b69a39bb..abd90d2ec 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/conf/InternalConfigHolder.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/conf/InternalConfigHolder.scala
@@ -17,26 +17,20 @@
package org.apache.streampark.common.conf
-import org.apache.streampark.common.util.{Logger, SystemPropertyUtils}
-
-import java.lang.{
- Boolean => JavaBool,
- Double => JavaDouble,
- Float => JavaFloat,
- Integer => JavaInt,
- Long => JavaLong
-}
+import java.lang.{Boolean => JavaBool, Double => JavaDouble, Float => JavaFloat, Integer => JavaInt, Long => JavaLong}
import java.util
import java.util.concurrent.ConcurrentHashMap
import javax.annotation.{Nonnull, Nullable}
+
import scala.collection.JavaConversions._
import scala.language.postfixOps
+import org.apache.streampark.common.util.{Logger, SystemPropertyUtils}
+
/**
* Thread-safe configuration storage containers.
* All configurations will be automatically initialized from the spring
* configuration items of the same name.
- *
*/
object InternalConfigHolder extends Logger {
@@ -176,13 +170,12 @@ object InternalConfigHolder extends Logger {
logInfo(
s"""registered configs:
|ConfigHub collected configs: ${configKeys.size}
- | ${configKeys.map(key => s"$key = ${if (key.contains("password")) ConfigConst.DEFAULT_DATAMASK_STRING else get(key)}").mkString("\n ")}""".stripMargin)
+ | ${configKeys.map(key => s"$key = ${if (key.contains("password")) ConfigConst.DEFAULT_DATAMASK_STRING else get(key)}").mkString(
+ "\n ")}""".stripMargin)
}
-
}
-
object Converter {
def convert[T](v: String, classType: Class[_]): T = {
@@ -203,5 +196,3 @@ object Converter {
}
}
}
-
-
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/conf/InternalOption.scala b/streampark-common/src/main/scala/org/apache/streampark/common/conf/InternalOption.scala
index 084566639..e27ac0258 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/conf/InternalOption.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/conf/InternalOption.scala
@@ -17,9 +17,7 @@
package org.apache.streampark.common.conf
-
/**
- *
* Internal use of the system
*
* @param key key of configuration that consistent with the spring config.
@@ -27,9 +25,6 @@ package org.apache.streampark.common.conf
* @param classType the class type of value. <b>please use java class type</b>.
* @param description description of configuration.
*/
-case class InternalOption(key: String,
- defaultValue: Any,
- classType: Class[_],
- description: String = "") {
+case class InternalOption(key: String, defaultValue: Any, classType: Class[_], description: String = "") {
InternalConfigHolder.register(this)
}
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/conf/K8sFlinkConfig.scala b/streampark-common/src/main/scala/org/apache/streampark/common/conf/K8sFlinkConfig.scala
index 84be26f57..c786e5862 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/conf/K8sFlinkConfig.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/conf/K8sFlinkConfig.scala
@@ -19,7 +19,6 @@ package org.apache.streampark.common.conf
/**
* Flink kubernetes Configuration
- *
*/
object K8sFlinkConfig {
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/conf/Workspace.scala b/streampark-common/src/main/scala/org/apache/streampark/common/conf/Workspace.scala
index a8add22a8..40a1009fb 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/conf/Workspace.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/conf/Workspace.scala
@@ -16,11 +16,10 @@
*/
package org.apache.streampark.common.conf
-import org.apache.streampark.common.enums.StorageType
-import org.apache.streampark.common.util.{HdfsUtils, SystemPropertyUtils}
-
import java.net.URI
+import org.apache.streampark.common.enums.StorageType
+import org.apache.streampark.common.util.{HdfsUtils, SystemPropertyUtils}
object Workspace {
@@ -30,7 +29,6 @@ object Workspace {
lazy val remote: Workspace = Workspace.of(StorageType.HDFS)
-
private[this] lazy val localWorkspace = local.WORKSPACE
/**
@@ -131,4 +129,3 @@ case class Workspace(storageType: StorageType) {
lazy val APP_JARS = s"$WORKSPACE/jars"
}
-
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/domain/FlinkVersion.scala b/streampark-common/src/main/scala/org/apache/streampark/common/domain/FlinkVersion.scala
index 113a759a6..dc00339ea 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/domain/FlinkVersion.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/domain/FlinkVersion.scala
@@ -16,15 +16,16 @@
*/
package org.apache.streampark.common.domain
-import org.apache.streampark.common.util.{CommandUtils, Logger}
-
import java.io.File
import java.net.{URL => NetURL}
import java.util.concurrent.atomic.{AtomicBoolean, AtomicReference}
import java.util.function.Consumer
import java.util.regex.Pattern
+
import scala.collection.JavaConversions._
+import org.apache.streampark.common.util.{CommandUtils, Logger}
+
/**
* @param flinkHome actual flink home that must be a readable local path
*/
@@ -42,7 +43,7 @@ class FlinkVersion(val flinkHome: String) extends java.io.Serializable with Logg
matcher.group(1);
} else {
// flink 1.15 + on support scala 2.12
- "2.12"
+ "2.12"
}
}
@@ -63,16 +64,19 @@ class FlinkVersion(val flinkHome: String) extends java.io.Serializable with Logg
val cmd = List(s"java -classpath ${flinkDistJar.getAbsolutePath} org.apache.flink.client.cli.CliFrontend --version")
val success = new AtomicBoolean(false)
val buffer = new StringBuilder
- CommandUtils.execute(flinkLib.getAbsolutePath, cmd, new Consumer[String]() {
- override def accept(out: String): Unit = {
- buffer.append(out).append("\n")
- val matcher = FLINK_VERSION_PATTERN.matcher(out)
- if (matcher.find) {
- success.set(true)
- flinkVersion.set(matcher.group(1))
+ CommandUtils.execute(
+ flinkLib.getAbsolutePath,
+ cmd,
+ new Consumer[String]() {
+ override def accept(out: String): Unit = {
+ buffer.append(out).append("\n")
+ val matcher = FLINK_VERSION_PATTERN.matcher(out)
+ if (matcher.find) {
+ success.set(true)
+ flinkVersion.set(matcher.group(1))
+ }
}
- }
- })
+ })
logInfo(buffer.toString())
if (!success.get()) {
throw new IllegalStateException(s"[StreamPark] parse flink version failed. $buffer")
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/enums/RestartStrategy.scala b/streampark-common/src/main/scala/org/apache/streampark/common/enums/RestartStrategy.scala
index 1b0dfd3a1..5de275ca2 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/enums/RestartStrategy.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/enums/RestartStrategy.scala
@@ -21,12 +21,12 @@ object RestartStrategy extends Enumeration {
val `fixed-delay`, `failure-rate`, `none` = Value
/**
- *
* @param name
* @return
*/
def byName(name: String): Value = {
- if (name == null) null else {
+ if (name == null) null
+ else {
values.find(_.toString.replace("$minus", "-").equalsIgnoreCase(name)) match {
case Some(v) => v
case _ => throw new IllegalArgumentException("[StreamPark] RestartStrategy must be (fixed-delay|failure-rate|none)")
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/fs/HdfsOperator.scala b/streampark-common/src/main/scala/org/apache/streampark/common/fs/HdfsOperator.scala
index 79b8d10c1..9659ce451 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/fs/HdfsOperator.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/fs/HdfsOperator.scala
@@ -59,5 +59,3 @@ object HdfsOperator extends FsOperator with Logger {
}
}
-
-
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/fs/LfsOperator.scala b/streampark-common/src/main/scala/org/apache/streampark/common/fs/LfsOperator.scala
index 377e137c7..7b37418bf 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/fs/LfsOperator.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/fs/LfsOperator.scala
@@ -17,13 +17,14 @@
package org.apache.streampark.common.fs
-import org.apache.streampark.common.util.Logger
-import org.apache.streampark.common.util.Utils.{isAnyBank, notEmpty}
+import java.io.{File, FileInputStream}
+
import org.apache.commons.codec.digest.DigestUtils
import org.apache.commons.io.{FileUtils, IOUtils}
import org.apache.commons.lang3.StringUtils
-import java.io.{File, FileInputStream}
+import org.apache.streampark.common.util.Logger
+import org.apache.streampark.common.util.Utils.{isAnyBank, notEmpty}
/**
* Local File System (aka LFS) Operator
@@ -93,7 +94,8 @@ object LfsOperator extends FsOperator with Logger {
require(srcFile.getCanonicalPath != dstFile.getCanonicalPath)
- val shouldCopy = if (overwrite) true; else {
+ val shouldCopy = if (overwrite) true;
+ else {
if (!dstFile.exists()) true else dstFile.getName != srcFile.getName
}
@@ -103,7 +105,6 @@ object LfsOperator extends FsOperator with Logger {
}
}
-
override def copyDir(srcPath: String, dstPath: String, delSrc: Boolean, overwrite: Boolean): Unit = {
if (isAnyBank(srcPath, dstPath)) return
val srcFile = new File(srcPath)
@@ -148,8 +149,4 @@ object LfsOperator extends FsOperator with Logger {
}
}
-
}
-
-
-
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
index e4c3a9587..6b24b9e54 100644
--- 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
@@ -19,7 +19,6 @@ package org.apache.streampark.common.util
import java.util
-
object AssertUtils {
/**
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/CURLBuilder.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/CURLBuilder.scala
index 22d87fa2f..ef8bde57d 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/CURLBuilder.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/CURLBuilder.scala
@@ -17,6 +17,7 @@
package org.apache.streampark.common.util
import java.util
+
import scala.collection.JavaConversions._
class CURLBuilder(val url: String) {
@@ -36,7 +37,7 @@ class CURLBuilder(val url: String) {
}
def build: String = {
- require( url != null, "[StreamPark] cURL build failed, url must not be null")
+ require(url != null, "[StreamPark] cURL build failed, url must not be null")
val cURL = new StringBuilder("curl -X POST ")
cURL.append(String.format("'%s' \\\n", url))
for (headerKey <- headers.keySet) {
@@ -50,4 +51,3 @@ class CURLBuilder(val url: String) {
}
}
-
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/ClassLoaderUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/ClassLoaderUtils.scala
index 43348fbee..f0766e6c0 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/ClassLoaderUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/ClassLoaderUtils.scala
@@ -19,6 +19,7 @@ package org.apache.streampark.common.util
import java.io.File
import java.net.{URL, URLClassLoader}
import java.util.function.Supplier
+
import scala.util.Try
object ClassLoaderUtils extends Logger {
@@ -115,7 +116,8 @@ object ClassLoaderUtils extends Logger {
}
}
- @throws[Exception] private[this] def addURL(file: File): Unit = {
+ @throws[Exception]
+ private[this] def addURL(file: File): Unit = {
val classLoader = ClassLoader.getSystemClassLoader
classLoader match {
case c if c.isInstanceOf[URLClassLoader] =>
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/CommandUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/CommandUtils.scala
index e327ec4e1..0d83e117c 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/CommandUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/CommandUtils.scala
@@ -20,12 +20,14 @@ import java.io._
import java.lang.{Iterable => JavaIterable}
import java.util.Scanner
import java.util.function.Consumer
+
import scala.collection.JavaConversions._
import scala.util.{Failure, Success, Try}
object CommandUtils extends Logger {
- @throws[Exception] def execute(command: String): (Int, String) = {
+ @throws[Exception]
+ def execute(command: String): (Int, String) = {
Try {
val buffer = new StringBuffer()
val process: Process = Runtime.getRuntime.exec(command)
@@ -49,7 +51,7 @@ object CommandUtils extends Logger {
require(commands != null && commands.nonEmpty, "[StreamPark] CommandUtils.execute: commands must not be null.")
logDebug(s"Command execute:\n${commands.mkString("\n")} ")
- //1) init
+ // 1) init
lazy val process = {
val interpreters = if (Utils.isWindows) List("cmd", "/k") else List("/bin/bash")
val builder = new ProcessBuilder(interpreters).redirectErrorStream(true)
@@ -71,7 +73,7 @@ object CommandUtils extends Logger {
out.close()
}
- //3) out
+ // 3) out
def output(): Unit = {
val scanner = new Scanner(process.getInputStream)
while (scanner.hasNextLine) {
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/CompletableFutureUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/CompletableFutureUtils.scala
index 40378bda5..cc5bfdeb9 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/CompletableFutureUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/CompletableFutureUtils.scala
@@ -17,7 +17,7 @@
package org.apache.streampark.common.util
-import java.util.concurrent.{Callable, CompletableFuture, ScheduledThreadPoolExecutor, ThreadFactory, TimeUnit, TimeoutException}
+import java.util.concurrent.{Callable, CompletableFuture, ScheduledThreadPoolExecutor, ThreadFactory, TimeoutException, TimeUnit}
import java.util.function.{Consumer, Function => JavaFunc}
object CompletableFutureUtils {
@@ -41,17 +41,21 @@ object CompletableFutureUtils {
def setTimeout[T](timeout: Long, unit: TimeUnit): CompletableFuture[T] = {
val result = new CompletableFuture[T]
- completableDelayer.schedule(new Callable[Boolean] {
- override def call(): Boolean = result.completeExceptionally(new TimeoutException)
- }, timeout, unit)
+ completableDelayer.schedule(
+ new Callable[Boolean] {
+ override def call(): Boolean = result.completeExceptionally(new TimeoutException)
+ },
+ timeout,
+ unit)
result
}
- def supplyTimeout[T](future: CompletableFuture[T],
- timeout: Long,
- unit: TimeUnit,
- handle: JavaFunc[T, T],
- exceptionally: JavaFunc[Throwable, T]): CompletableFuture[T] = {
+ def supplyTimeout[T](
+ future: CompletableFuture[T],
+ timeout: Long,
+ unit: TimeUnit,
+ handle: JavaFunc[T, T],
+ exceptionally: JavaFunc[Throwable, T]): CompletableFuture[T] = {
future.applyToEither(setTimeout(timeout, unit), handle).exceptionally(exceptionally)
}
@@ -65,18 +69,21 @@ object CompletableFutureUtils {
* @param handle The handler will be called when future complete normally before timeout.
* @param exceptionally The exceptionally will be called when future completed exceptionally or future isn't done after timeout.
*/
- def runTimeout[T](future: CompletableFuture[T],
- timeout: Long,
- unit: TimeUnit,
- handle: Consumer[T],
- exceptionally: Consumer[Throwable]): CompletableFuture[Unit] = {
- future.applyToEither(setTimeout(timeout, unit), new JavaFunc[T, Unit] {
- override def apply(t: T): Unit = {
- if (handle != null) {
- handle.accept(t)
+ def runTimeout[T](
+ future: CompletableFuture[T],
+ timeout: Long,
+ unit: TimeUnit,
+ handle: Consumer[T],
+ exceptionally: Consumer[Throwable]): CompletableFuture[Unit] = {
+ future.applyToEither(
+ setTimeout(timeout, unit),
+ new JavaFunc[T, Unit] {
+ override def apply(t: T): Unit = {
+ if (handle != null) {
+ handle.accept(t)
+ }
}
- }
- }).exceptionally(new JavaFunc[Throwable, Unit] {
+ }).exceptionally(new JavaFunc[Throwable, Unit] {
override def apply(t: Throwable): Unit = {
if (exceptionally != null) {
exceptionally.accept(t)
@@ -85,16 +92,19 @@ object CompletableFutureUtils {
})
}
- def runTimeout[T](future: CompletableFuture[T],
- timeout: Long,
- unit: TimeUnit): CompletableFuture[Unit] = {
- runTimeout(future, timeout, unit, null, new Consumer[Throwable] {
- override def accept(t: Throwable): Unit = {
- if (!future.isDone) {
- future.cancel(true)
+ def runTimeout[T](future: CompletableFuture[T], timeout: Long, unit: TimeUnit): CompletableFuture[Unit] = {
+ runTimeout(
+ future,
+ timeout,
+ unit,
+ null,
+ new Consumer[Throwable] {
+ override def accept(t: Throwable): Unit = {
+ if (!future.isDone) {
+ future.cancel(true)
+ }
}
- }
- })
+ })
}
}
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/ConfigUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/ConfigUtils.scala
index abb6a5932..d9783871f 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/ConfigUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/ConfigUtils.scala
@@ -16,13 +16,14 @@
*/
package org.apache.streampark.common.util
-import org.apache.streampark.common.conf.ConfigConst._
+import java.util.{Map => JavaMap, Properties}
-import java.util.{Properties, Map => JavaMap}
import scala.collection.JavaConversions._
import scala.collection.immutable.{Map => ScalaMap}
import scala.util.Try
+import org.apache.streampark.common.conf.ConfigConst._
+
object ConfigUtils {
def getConf(parameter: JavaMap[String, String], prefix: String = "", addfix: String = "")(implicit alias: String = ""): Properties = {
@@ -39,7 +40,8 @@ object ConfigUtils {
def getKafkaSinkConf(parameter: JavaMap[String, String], topic: String = "", alias: String = ""): Properties = {
val prefix = KAFKA_SINK_PREFIX + alias
val param: ScalaMap[String, String] = filterParam(parameter, if (prefix.endsWith(".")) prefix else s"$prefix.")
- if (param.isEmpty) throw new IllegalArgumentException(s"${topic} init error...") else {
+ if (param.isEmpty) throw new IllegalArgumentException(s"${topic} init error...")
+ else {
val kafkaProperty = new Properties()
param.foreach(x => kafkaProperty.put(x._1, x._2.trim))
val _topic = topic match {
@@ -61,7 +63,6 @@ object ConfigUtils {
}
/**
- *
* @param parameter
* @param dialect
* @param alias
@@ -79,7 +80,8 @@ object ConfigUtils {
(driver, url, user, password) match {
case (x, y, _, _) if x == null || y == null => throw new IllegalArgumentException(s"Jdbc instance:$prefix error,[driver|url] must not be null")
- case (_, _, x, y) if (x != null && y == null) || (x == null && y != null) => throw new IllegalArgumentException("Jdbc instance:" + prefix + " error, [user|password] must be all null,or all not null ")
+ case (_, _, x, y) if (x != null && y == null) || (x == null && y != null) =>
+ throw new IllegalArgumentException("Jdbc instance:" + prefix + " error, [user|password] must be all null,or all not null ")
case _ =>
}
val param: ScalaMap[String, String] = filterParam(parameter, prefix)
@@ -96,8 +98,7 @@ object ConfigUtils {
.toMap
.filter(x => x._1.startsWith(fix) && Try(x._2 != null).getOrElse(false))
.flatMap(x =>
- Some(x._1.substring(fix.length).replaceFirst("^\\.", "") -> x._2)
- )
+ Some(x._1.substring(fix.length).replaceFirst("^\\.", "") -> x._2))
}
}
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/DateUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/DateUtils.scala
index 948065023..e36396218 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/DateUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/DateUtils.scala
@@ -21,8 +21,8 @@ import java.time.{Duration, LocalDateTime}
import java.time.format.DateTimeFormatter
import java.util._
import java.util.concurrent.TimeUnit
-import scala.util._
+import scala.util._
object DateUtils {
@@ -71,7 +71,8 @@ object DateUtils {
}
def format(date: Date = new Date(), fmt: String = fullFormat, timeZone: TimeZone = TimeZone.getDefault): String = {
- if (date == null) null else {
+ if (date == null) null
+ else {
val simpleDateFormat = new SimpleDateFormat(fmt)
simpleDateFormat.setTimeZone(timeZone)
simpleDateFormat.format(date)
@@ -196,7 +197,8 @@ object DateUtils {
format.format(date)
}
- @throws[ParseException] def formatCSTTime(date: String, format: String): String = {
+ @throws[ParseException]
+ def formatCSTTime(date: String, format: String): String = {
val sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US)
val d = sdf.parse(date)
DateUtils.getDateFormat(d, format)
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/DependencyUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/DependencyUtils.scala
index 1cdb2ac39..b311ad238 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/DependencyUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/DependencyUtils.scala
@@ -17,6 +17,11 @@
package org.apache.streampark.common.util
+import java.io.{File, IOException}
+import java.text.ParseException
+import java.util.UUID
+import java.util.function.Consumer
+
import org.apache.ivy.Ivy
import org.apache.ivy.core.LogOptions
import org.apache.ivy.core.module.descriptor._
@@ -30,40 +35,33 @@ import org.apache.ivy.plugins.repository.file.FileRepository
import org.apache.ivy.plugins.resolver.{ChainResolver, FileSystemResolver, IBiblioResolver}
import org.apache.ivy.util.{DefaultMessageLogger, Message}
-import java.io.{File, IOException}
-import java.text.ParseException
-import java.util.UUID
-import java.util.function.Consumer
-
object DependencyUtils {
- @throws[Exception] def resolveMavenDependencies(
- packagesExclusions: String,
- packages: String,
- repositories: String,
- ivyRepoPath: String,
- ivySettingsPath: String,
- outCallback: Consumer[String]): List[String] = {
+ @throws[Exception]
+ def resolveMavenDependencies(
+ packagesExclusions: String,
+ packages: String,
+ repositories: String,
+ ivyRepoPath: String,
+ ivySettingsPath: String,
+ outCallback: Consumer[String]): List[String] = {
val exclusions: Seq[String] = if (Utils.isEmpty(packagesExclusions)) Nil else packagesExclusions.split(",")
// Create the IvySettings, either load from file or build defaults
val ivySettings = ivySettingsPath match {
case null => buildIvySettings(
- Option(repositories),
- Option(ivyRepoPath),
- outCallback
- )
+ Option(repositories),
+ Option(ivyRepoPath),
+ outCallback)
case path => loadIvySettings(
- path,
- Option(repositories),
- Option(ivyRepoPath),
- outCallback
- )
+ path,
+ Option(repositories),
+ Option(ivyRepoPath),
+ outCallback)
}
resolveMavenCoordinates(packages, ivySettings, exclusions, outCallback)
}
-
/**
* Represents a Maven Coordinate
*
@@ -87,20 +85,16 @@ object DependencyUtils {
val splits = p.replace("/", ":").split(":")
require(
splits.length == 3,
- s"[StreamPark] DependencyUtils.extractMavenCoordinates: Provided Maven Coordinates must be in the form 'groupId:artifactId:version'. The coordinate provided is: $p"
- )
+ s"[StreamPark] DependencyUtils.extractMavenCoordinates: Provided Maven Coordinates must be in the form 'groupId:artifactId:version'. The coordinate provided is: $p")
require(
splits(0) != null && splits(0).trim.nonEmpty,
- s"[StreamPark] DependencyUtils.extractMavenCoordinates: The groupId cannot be null or be whitespace. The groupId provided is: ${splits(0)}"
- )
+ s"[StreamPark] DependencyUtils.extractMavenCoordinates: The groupId cannot be null or be whitespace. The groupId provided is: ${splits(0)}")
require(
splits(1) != null && splits(1).trim.nonEmpty,
- s"[StreamPark] DependencyUtils.extractMavenCoordinates: The artifactId cannot be null or be whitespace. The artifactId provided is: ${splits(1)}"
- )
+ s"[StreamPark] DependencyUtils.extractMavenCoordinates: The artifactId cannot be null or be whitespace. The artifactId provided is: ${splits(1)}")
require(
splits(2) != null && splits(2).trim.nonEmpty,
- s"[StreamPark] DependencyUtils.extractMavenCoordinates: The version cannot be null or be whitespace. The version provided is: ${splits(2)}"
- )
+ s"[StreamPark] DependencyUtils.extractMavenCoordinates: The version cannot be null or be whitespace. The version provided is: ${splits(2)}")
MavenCoordinate(splits(0), splits(1), splits(2))
}
}
@@ -138,8 +132,7 @@ object DependencyUtils {
"[module]",
"[revision]",
"ivys",
- "ivy.xml"
- ).mkString(File.separator)
+ "ivy.xml").mkString(File.separator)
localIvy.addIvyPattern(ivyPattern)
val artifactPattern = Seq(
localIvyRoot.getAbsolutePath,
@@ -147,8 +140,7 @@ object DependencyUtils {
"[module]",
"[revision]",
"[type]s",
- "[artifact](-[classifier]).[ext]"
- ).mkString(File.separator)
+ "[artifact](-[classifier]).[ext]").mkString(File.separator)
localIvy.addArtifactPattern(artifactPattern)
localIvy.setName("local-ivy-cache")
@@ -171,8 +163,7 @@ object DependencyUtils {
* @param cacheDirectory directory where jars are cached
* @return a comma-delimited list of paths for the dependencies
*/
- def resolveDependencyPaths(artifacts: Array[AnyRef],
- cacheDirectory: File): List[String] = {
+ def resolveDependencyPaths(artifacts: Array[AnyRef], cacheDirectory: File): List[String] = {
artifacts.map { artifactInfo =>
val artifact = artifactInfo.asInstanceOf[Artifact].getModuleRevisionId
s"${cacheDirectory.getAbsolutePath}${File.separator}${artifact.getOrganisation}_${artifact.getName}-${artifact.getRevision}.jar"
@@ -180,10 +171,7 @@ object DependencyUtils {
}
/** Adds the given maven coordinates to Ivy's module descriptor. */
- def addDependenciesToIvy(md: DefaultModuleDescriptor,
- artifacts: Seq[MavenCoordinate],
- ivyConfName: String,
- outCallback: Consumer[String]): Unit = {
+ def addDependenciesToIvy(md: DefaultModuleDescriptor, artifacts: Seq[MavenCoordinate], ivyConfName: String, outCallback: Consumer[String]): Unit = {
artifacts.foreach { mvn =>
val ri = ModuleRevisionId.newInstance(mvn.groupId, mvn.artifactId, mvn.version)
val dd = new DefaultDependencyDescriptor(ri, false, false)
@@ -195,9 +183,9 @@ object DependencyUtils {
/** Add exclusion rules for dependencies already included in the flink-dist */
def addExclusionRules(
- ivySettings: IvySettings,
- ivyConfName: String,
- md: DefaultModuleDescriptor): Unit = {
+ ivySettings: IvySettings,
+ ivyConfName: String,
+ md: DefaultModuleDescriptor): Unit = {
// Add scala exclusion rule
md.addExcludeRule(createExclusion("*:scala-library:*", ivySettings, ivyConfName))
}
@@ -231,11 +219,10 @@ object DependencyUtils {
* @return An IvySettings object
*/
def loadIvySettings(
- settingsFile: String,
- remoteRepos: Option[String],
- ivyPath: Option[String],
- outCallback: Consumer[String]
- ): IvySettings = {
+ settingsFile: String,
+ remoteRepos: Option[String],
+ ivyPath: Option[String],
+ outCallback: Consumer[String]): IvySettings = {
val file = new File(settingsFile)
require(file.exists(), s"[StreamPark] DependencyUtils.loadIvySettings: Ivy settings file $file does not exist")
require(file.isFile, s"[StreamPark] DependencyUtils.loadIvySettings: Ivy settings file $file is not a normal file")
@@ -243,7 +230,7 @@ object DependencyUtils {
try {
ivySettings.load(file)
} catch {
- case e@(_: IOException | _: ParseException) =>
+ case e @ (_: IOException | _: ParseException) =>
throw new RuntimeException(s"DependencyUtils.loadIvySettings: Failed when loading Ivy settings from $settingsFile", e)
}
processIvyPathArg(ivySettings, ivyPath)
@@ -288,18 +275,16 @@ object DependencyUtils {
ModuleRevisionId.newInstance(
"org.apache.streampark",
s"dependency-parent-${UUID.randomUUID.toString}",
- "1.0")
- )
+ "1.0"))
private def clearIvyResolutionFiles(
- mdId: ModuleRevisionId,
- ivySettings: IvySettings,
- ivyConfName: String): Unit = {
+ mdId: ModuleRevisionId,
+ ivySettings: IvySettings,
+ ivyConfName: String): Unit = {
val currentResolutionFiles = Seq(
s"${mdId.getOrganisation}-${mdId.getName}-$ivyConfName.xml",
s"resolved-${mdId.getOrganisation}-${mdId.getName}-${mdId.getRevision}.xml",
- s"resolved-${mdId.getOrganisation}-${mdId.getName}-${mdId.getRevision}.properties"
- )
+ s"resolved-${mdId.getOrganisation}-${mdId.getName}-${mdId.getRevision}.properties")
currentResolutionFiles.foreach { filename =>
new File(ivySettings.getDefaultCache, filename).delete()
}
@@ -314,14 +299,15 @@ object DependencyUtils {
* @return The comma-delimited path to the jars of the given maven artifacts including their
* transitive dependencies
*/
- @throws[Exception] def resolveMavenCoordinates(
- coordinates: String,
- ivySettings: IvySettings,
- exclusions: Seq[String] = Nil,
- outCallback: Consumer[String],
- isTest: Boolean = false
- ): List[String] = {
- if (Utils.isEmpty(coordinates)) List.empty[String] else {
+ @throws[Exception]
+ def resolveMavenCoordinates(
+ coordinates: String,
+ ivySettings: IvySettings,
+ exclusions: Seq[String] = Nil,
+ outCallback: Consumer[String],
+ isTest: Boolean = false): List[String] = {
+ if (Utils.isEmpty(coordinates)) List.empty[String]
+ else {
try {
setDefaultLogger(outCallback)
// To prevent ivy from logging to system out
@@ -368,8 +354,7 @@ object DependencyUtils {
ivy.retrieve(
rr.getModuleDescriptor.getModuleRevisionId,
s"${packagesDirectory.getAbsolutePath}${File.separator}[organization]_[artifact]-[revision](-[classifier]).[ext]",
- retrieveOptions.setConfs(Array(ivyConfName))
- )
+ retrieveOptions.setConfs(Array(ivyConfName)))
val paths = resolveDependencyPaths(rr.getArtifacts.toArray, packagesDirectory)
val mdId = md.getModuleRevisionId
clearIvyResolutionFiles(mdId, ivySettings, ivyConfName)
@@ -381,9 +366,9 @@ object DependencyUtils {
}
private def createExclusion(
- coords: String,
- ivySettings: IvySettings,
- ivyConfName: String): ExcludeRule = {
+ coords: String,
+ ivySettings: IvySettings,
+ ivyConfName: String): ExcludeRule = {
val c = extractMavenCoordinates(coords).head
val id = new ArtifactId(new ModuleId(c.groupId, c.artifactId), "*", "*", "*")
val rule = new DefaultExcludeRule(id, ivySettings.getMatcher("glob"), null)
@@ -415,5 +400,4 @@ object DependencyUtils {
})
}
-
}
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
index 7d2605194..9a665af2f 100644
--- 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
@@ -16,20 +16,20 @@
*/
package org.apache.streampark.common.util
-import org.apache.commons.lang3.ArrayUtils
-
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 java.util.{Optional, StringTokenizer}
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)"
@@ -96,7 +96,10 @@ object ExceptionUtils {
* @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 = {
+ @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]
@@ -316,7 +319,8 @@ object ExceptionUtils {
* @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 {
+ if (throwable == null || searchType == null) Optional.empty[T]
+ else {
var t = throwable
var r: Optional[T] = null
while (t != null && r == null) {
@@ -328,7 +332,6 @@ object ExceptionUtils {
}
}
-
/**
* Checks whether a throwable chain contains an exception matching a predicate and returns it.
*
@@ -337,7 +340,8 @@ object ExceptionUtils {
* @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 {
+ if (throwable == null || predicate == null) Optional.empty[Throwable]
+ else {
var t = throwable
var r: Optional[Throwable] = null
while (t != null && r == null) {
@@ -357,14 +361,14 @@ object ExceptionUtils {
* @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 {
+ 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
+ } else t = t.getCause
}
r
}
@@ -415,7 +419,6 @@ object ExceptionUtils {
}
/**
- *
* @param stackTrace
* @return
*/
@@ -430,4 +433,3 @@ object ExceptionUtils {
}
}
-
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/FileUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/FileUtils.scala
index f8553f76b..27ff9e4be 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/FileUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/FileUtils.scala
@@ -19,6 +19,7 @@ package org.apache.streampark.common.util
import java.io._
import java.net.URL
import java.util
+
import scala.collection.JavaConversions._
object FileUtils extends org.apache.commons.io.FileUtils {
@@ -43,7 +44,6 @@ object FileUtils extends org.apache.commons.io.FileUtils {
maps.put("44656C69766572792D646174653A", "eml")
maps.put("D0CF11E0A1B11AE10000", "doc")
-
maps.put("D0CF11E0A1B11AE10000", "vsd")
maps.put("5374616E64617264204A", "mdb")
maps.put("252150532D41646F6265", "ps")
@@ -131,7 +131,8 @@ object FileUtils extends org.apache.commons.io.FileUtils {
return tempDir
}
}
- throw new IllegalStateException(s"[StreamPark] Failed to create directory within $TEMP_DIR_ATTEMPTS attempts (tried $baseName 0 to $baseName ${TEMP_DIR_ATTEMPTS - 1})")
+ throw new IllegalStateException(
+ s"[StreamPark] Failed to create directory within $TEMP_DIR_ATTEMPTS attempts (tried $baseName 0 to $baseName ${TEMP_DIR_ATTEMPTS - 1})")
}
def exists(path: String): Unit = {
@@ -178,7 +179,8 @@ object FileUtils extends org.apache.commons.io.FileUtils {
case (a, b) =>
val first = new BufferedInputStream(new FileInputStream(a))
val second = new BufferedInputStream(new FileInputStream(b))
- if (first.available() != second.available()) false; else {
+ if (first.available() != second.available()) false;
+ else {
while (true) {
val firRead = first.read()
val secRead = second.read()
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/FlinkClientUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/FlinkClientUtils.scala
index 488578938..c37931988 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/FlinkClientUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/FlinkClientUtils.scala
@@ -16,19 +16,18 @@
*/
package org.apache.streampark.common.util
+import java.net.{InetAddress, InetSocketAddress, ServerSocket}
+
import org.apache.flink.api.common.Plan
import org.apache.flink.client.program.{PackagedProgram, PackagedProgramUtils, ProgramInvocationException}
import org.apache.flink.configuration.{Configuration, JobManagerOptions}
+import org.apache.flink.optimizer.{DataStatistics, Optimizer}
import org.apache.flink.optimizer.costs.DefaultCostEstimator
import org.apache.flink.optimizer.plan.OptimizedPlan
import org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator
-import org.apache.flink.optimizer.{DataStatistics, Optimizer}
-
-import java.net.{InetAddress, InetSocketAddress, ServerSocket}
object FlinkClientUtils {
-
/**
* getExecutionPlan
*
@@ -36,7 +35,8 @@ object FlinkClientUtils {
* @throws
* @return
*/
- @throws[ProgramInvocationException] def getExecutionPlan(packagedProgram: PackagedProgram): String = {
+ @throws[ProgramInvocationException]
+ def getExecutionPlan(packagedProgram: PackagedProgram): String = {
require(packagedProgram != null, "[StreamPark] FlinkClientUtils.getExecutionPlan: packagedProgram must not be null")
val address: InetAddress = InetAddress.getLocalHost
val jmAddress = new InetSocketAddress(address, new ServerSocket(0).getLocalPort)
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/FlinkUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/FlinkUtils.scala
index 28fa04063..b0b90bc98 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/FlinkUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/FlinkUtils.scala
@@ -16,16 +16,16 @@
*/
package org.apache.streampark.common.util
+import java.io.File
+import java.time.Duration
+import java.util
+
import org.apache.flink.api.common.state.{ListState, ListStateDescriptor}
import org.apache.flink.api.common.typeinfo.TypeInformation
import org.apache.flink.runtime.state.FunctionInitializationContext
import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions
import org.apache.flink.util.TimeUtils
-import java.io.File
-import java.time.Duration
-import java.util
-
object FlinkUtils {
def getUnionListState[R: TypeInformation](context: FunctionInitializationContext, descriptorName: String): ListState[R] = {
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/HBaseClient.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/HBaseClient.scala
index f8f7ab851..ed42ba99d 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/HBaseClient.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/HBaseClient.scala
@@ -16,15 +16,16 @@
*/
package org.apache.streampark.common.util
-import org.apache.streampark.common.conf.ConfigConst._
+import java.util.Properties
+
+import scala.collection.JavaConversions._
+
import org.apache.hadoop.conf.Configuration
-import org.apache.hadoop.hbase.client.{Connection, ConnectionFactory, Table}
import org.apache.hadoop.hbase.{HBaseConfiguration, TableName}
+import org.apache.hadoop.hbase.client.{Connection, ConnectionFactory, Table}
import org.apache.hadoop.security.UserGroupInformation
-import java.util.Properties
-import scala.collection.JavaConversions._
-
+import org.apache.streampark.common.conf.ConfigConst._
class HBaseClient(func: () => Connection) extends Serializable {
lazy val connection: Connection = func()
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/HadoopConfigUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/HadoopConfigUtils.scala
index 8c67ea77e..c8d16e024 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/HadoopConfigUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/HadoopConfigUtils.scala
@@ -16,21 +16,21 @@
*/
package org.apache.streampark.common.util
-import com.google.common.collect.Maps
-import org.apache.streampark.common.fs.LfsOperator
-import org.apache.commons.io.{FileUtils => ApacheFileUtils}
-
import java.io.File
import java.util.{Collections, Map => JavaMap, Optional => JOption}
+
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
import scala.collection.immutable.ListMap
import scala.util.{Failure, Success, Try}
+import com.google.common.collect.Maps
+import org.apache.commons.io.{FileUtils => ApacheFileUtils}
+
+import org.apache.streampark.common.fs.LfsOperator
/**
* Hadoop client configuration tools mainly for flink use.
- *
*/
object HadoopConfigUtils {
@@ -123,15 +123,13 @@ object HadoopConfigUtils {
* Read system hive config to Map
*/
def readSystemHiveConf: JavaMap[String, String] = {
- getSystemHiveConfDir.map(
- confDir =>
- LfsOperator.listDir(confDir)
- .filter(f => HIVE_CLIENT_CONF_FILES.contains(f.getName))
- .map(f => f.getName -> ApacheFileUtils.readFileToString(f, "UTF-8"))
- .toMap.asJava)
+ getSystemHiveConfDir.map(confDir =>
+ LfsOperator.listDir(confDir)
+ .filter(f => HIVE_CLIENT_CONF_FILES.contains(f.getName))
+ .map(f => f.getName -> ApacheFileUtils.readFileToString(f, "UTF-8"))
+ .toMap.asJava)
.getOrElse(Collections.emptyMap[String, String]())
}
-
}
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/HadoopUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/HadoopUtils.scala
index cc24fa5c3..9b98f27a2 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/HadoopUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/HadoopUtils.scala
@@ -17,8 +17,16 @@
package org.apache.streampark.common.util
-import org.apache.streampark.common.conf.ConfigConst._
-import org.apache.streampark.common.conf.{CommonConfig, ConfigConst, InternalConfigHolder}
+import java.io.{File, IOException}
+import java.security.PrivilegedAction
+import java.util
+import java.util.{Timer, TimerTask}
+import java.util.concurrent._
+import javax.security.auth.kerberos.KerberosTicket
+
+import scala.collection.JavaConversions._
+import scala.util.{Failure, Success, Try}
+
import org.apache.commons.collections.CollectionUtils
import org.apache.commons.lang3.StringUtils
import org.apache.hadoop.conf.Configuration
@@ -29,17 +37,9 @@ import org.apache.hadoop.service.Service.STATE
import org.apache.hadoop.yarn.api.records.ApplicationId
import org.apache.hadoop.yarn.client.api.YarnClient
import org.apache.hadoop.yarn.conf.YarnConfiguration
-import java.io.{File, IOException}
-import java.security.PrivilegedAction
-import java.util
-import java.util.concurrent._
-import java.util.{Timer, TimerTask}
-
-import javax.security.auth.kerberos.KerberosTicket
-
-import scala.collection.JavaConversions._
-import scala.util.{Failure, Success, Try}
+import org.apache.streampark.common.conf.{CommonConfig, ConfigConst, InternalConfigHolder}
+import org.apache.streampark.common.conf.ConfigConst._
object HadoopUtils extends Logger {
@@ -128,8 +128,8 @@ object HadoopUtils extends Logger {
val conf = new Configuration()
if (CollectionUtils.isNotEmpty(files)) {
files.foreach(x => conf.addResource(new Path(x.getAbsolutePath)))
- //HDFS default value change (with adding time unit) breaks old version MR tarball work with Hadoop 3.x
- //detail: https://issues.apache.org/jira/browse/HDFS-12920
+ // HDFS default value change (with adding time unit) breaks old version MR tarball work with Hadoop 3.x
+ // detail: https://issues.apache.org/jira/browse/HDFS-12920
val rewriteNames = List(
"dfs.blockreport.initialDelay",
"dfs.datanode.directoryscan.interval",
@@ -141,8 +141,7 @@ object HadoopUtils extends Logger {
"dfs.client.datanode-restart.timeout",
"dfs.ha.log-roll.period",
"dfs.ha.tail-edits.period",
- "dfs.datanode.bp-ready.timeout"
- )
+ "dfs.datanode.bp-ready.timeout")
rewriteNames.foreach(n => {
Option(conf.get(n)) match {
case Some(v) if v.matches("\\d+s$") => conf.set(n, v.dropRight(1))
@@ -165,7 +164,7 @@ object HadoopUtils extends Logger {
*/
def hadoopConf: Configuration = Option(reusableConf).getOrElse {
reusableConf = getConfigurationFromHadoopConfDir(hadoopConfDir)
- //add hadoopConfDir to classpath...you know why???
+ // add hadoopConfDir to classpath...you know why???
ClassLoaderUtils.loadResource(hadoopConfDir)
if (StringUtils.isBlank(reusableConf.get("hadoop.tmp.dir"))) {
@@ -207,13 +206,11 @@ object HadoopUtils extends Logger {
val keytab = kerberosConf.getOrElse(KEY_SECURITY_KERBEROS_KEYTAB, "").trim
require(
principal.nonEmpty && keytab.nonEmpty,
- s"$KEY_SECURITY_KERBEROS_PRINCIPAL and $KEY_SECURITY_KERBEROS_KEYTAB must not be empty"
- )
+ s"$KEY_SECURITY_KERBEROS_PRINCIPAL and $KEY_SECURITY_KERBEROS_KEYTAB must not be empty")
val krb5 = kerberosConf.getOrElse(
KEY_SECURITY_KERBEROS_KRB5_CONF,
- kerberosConf.getOrElse(KEY_JAVA_SECURITY_KRB5_CONF, "")
- ).trim
+ kerberosConf.getOrElse(KEY_JAVA_SECURITY_KRB5_CONF, "")).trim
if (krb5.nonEmpty) {
System.setProperty("java.security.krb5.conf", krb5)
@@ -249,12 +246,15 @@ object HadoopUtils extends Logger {
if (kerberosEnable) {
// reLogin...
val timer = new Timer()
- timer.schedule(new TimerTask {
- override def run(): Unit = {
- closeHadoop()
- logInfo(s"Check Kerberos Tgt And reLogin From Keytab Finish:refresh time: ${DateUtils.format()}")
- }
- }, tgtRefreshTime, tgtRefreshTime)
+ timer.schedule(
+ new TimerTask {
+ override def run(): Unit = {
+ closeHadoop()
+ logInfo(s"Check Kerberos Tgt And reLogin From Keytab Finish:refresh time: ${DateUtils.format()}")
+ }
+ },
+ tgtRefreshTime,
+ tgtRefreshTime)
}
fs
case Failure(e) =>
@@ -280,7 +280,8 @@ object HadoopUtils extends Logger {
ApplicationId.newInstance(timestampAndId(1).toLong, timestampAndId.last.toInt)
}
- @throws[IOException] def downloadJar(jarOnHdfs: String): String = {
+ @throws[IOException]
+ def downloadJar(jarOnHdfs: String): String = {
val tmpDir = FileUtils.createTempDir()
val fs = FileSystem.get(new Configuration)
val sourcePath = fs.makeQualified(new Path(jarOnHdfs))
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/HdfsUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/HdfsUtils.scala
index 256f86d84..6147285a7 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/HdfsUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/HdfsUtils.scala
@@ -16,16 +16,17 @@
*/
package org.apache.streampark.common.util
+import java.io.{ByteArrayOutputStream, FileWriter, IOException}
+import java.net.InetSocketAddress
+
+import scala.util.{Failure, Success, Try}
+
import org.apache.commons.codec.digest.DigestUtils
import org.apache.hadoop.fs._
import org.apache.hadoop.hdfs.DistributedFileSystem
import org.apache.hadoop.io.IOUtils
import org.apache.hadoop.ipc.RPC
-import java.io.{ByteArrayOutputStream, FileWriter, IOException}
-import java.net.InetSocketAddress
-import scala.util.{Failure, Success, Try}
-
object HdfsUtils extends Logger {
def getDefaultFS: String = HadoopUtils.hadoopConf.get(FileSystem.FS_DEFAULT_NAME_KEY)
@@ -40,7 +41,8 @@ object HdfsUtils extends Logger {
val srcPath = getPath(src)
val dstPath = getPath(dst)
val dstStatus = HadoopUtils.hdfs.getFileStatus(dstPath)
- val dstFinalPath = if (dstStatus.isFile) dstPath else {
+ val dstFinalPath = if (dstStatus.isFile) dstPath
+ else {
getPath(s"$dst/${srcPath.getName}")
}
FileUtil.copy(HadoopUtils.hdfs, srcPath, HadoopUtils.hdfs, dstFinalPath, delSrc, overwrite, HadoopUtils.hadoopConf)
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/HostsUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/HostsUtils.scala
index 20721c465..c2ec2dc91 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/HostsUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/HostsUtils.scala
@@ -17,13 +17,13 @@
package org.apache.streampark.common.util
-import io.netty.resolver.HostsFileParser
-
import java.net.InetAddress
import java.util.{Map => JavaMap}
+
import scala.collection.JavaConversions._
import scala.collection.immutable.ListMap
+import io.netty.resolver.HostsFileParser
object HostsUtils {
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/HttpClientUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/HttpClientUtils.scala
index b3b7db552..c000d6991 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/HttpClientUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/HttpClientUtils.scala
@@ -16,6 +16,12 @@
*/
package org.apache.streampark.common.util
+import java.nio.charset.{Charset, StandardCharsets}
+import java.security.Principal
+import java.util
+
+import scala.collection.JavaConversions._
+
import org.apache.http.NameValuePair
import org.apache.http.auth.{AuthSchemeProvider, AuthScope, Credentials}
import org.apache.http.client.config.{AuthSchemes, RequestConfig}
@@ -30,11 +36,6 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager
import org.apache.http.message.BasicNameValuePair
import org.apache.http.util.EntityUtils
-import java.nio.charset.{Charset, StandardCharsets}
-import java.security.Principal
-import java.util
-import scala.collection.JavaConversions._
-
object HttpClientUtils {
private[this] val defaultChart: Charset = StandardCharsets.UTF_8
@@ -109,16 +110,11 @@ object HttpClientUtils {
def httpPatchRequest(url: String, params: String): String = httpRequest(new HttpPatch(url), params)
-
- def httpPostRequest(url: String,
- params: util.Map[String, AnyRef],
- headers: util.Map[String, AnyRef] = Map.empty[String, AnyRef]): String = {
+ def httpPostRequest(url: String, params: util.Map[String, AnyRef], headers: util.Map[String, AnyRef] = Map.empty[String, AnyRef]): String = {
httpRequest(new HttpPost(url), headers, params)
}
- def httpPatchRequest(url: String,
- params: util.Map[String, AnyRef],
- headers: util.Map[String, AnyRef] = Map.empty[String, AnyRef]): String = {
+ def httpPatchRequest(url: String, params: util.Map[String, AnyRef], headers: util.Map[String, AnyRef] = Map.empty[String, AnyRef]): String = {
httpRequest(new HttpPatch(url), headers, params)
}
@@ -164,8 +160,7 @@ object HttpClientUtils {
getHttpResult(
getHttpGet(url, null, config),
- getHttpAuthClient
- )
+ getHttpAuthClient)
}
/**
@@ -185,5 +180,4 @@ object HttpClientUtils {
}
}
-
}
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/JdbcUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/JdbcUtils.scala
index 80df1288d..fa64679ce 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/JdbcUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/JdbcUtils.scala
@@ -16,25 +16,26 @@
*/
package org.apache.streampark.common.util
-import org.apache.streampark.common.conf.ConfigConst._
-import com.zaxxer.hikari.{HikariConfig, HikariDataSource}
-
import java.sql.{Connection, ResultSet, Statement}
import java.util.Properties
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.locks.ReentrantLock
+
import scala.collection.JavaConversions._
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.util.Try
+import com.zaxxer.hikari.{HikariConfig, HikariDataSource}
+
+import org.apache.streampark.common.conf.ConfigConst._
+
/**
* Based on the hikari connection pool implementation. Support multiple data sources,
* note that all modifications and additions are automatically committed transactions.
*/
object JdbcUtils {
-
private val lockMap: mutable.Map[String, ReentrantLock] = new ConcurrentHashMap[String, ReentrantLock]
private[this] val dataSourceHolder = new ConcurrentHashMap[String, HikariDataSource]
@@ -43,7 +44,8 @@ object JdbcUtils {
* Wrap all the fields of a query row of data into a List[Map]
*/
def select(sql: String, func: ResultSet => Unit = null)(implicit jdbcConfig: Properties): List[Map[String, _]] = {
- if (Try(sql.isEmpty).getOrElse(false)) List.empty else {
+ if (Try(sql.isEmpty).getOrElse(false)) List.empty
+ else {
val conn = getConnection(jdbcConfig)
var stmt: Statement = null
var result: ResultSet = null
@@ -67,7 +69,8 @@ object JdbcUtils {
}
if (array.isEmpty) List.empty else array.toList
} catch {
- case ex: Exception => ex.printStackTrace()
+ case ex: Exception =>
+ ex.printStackTrace()
List.empty
} finally {
close(result, stmt, conn)
@@ -101,7 +104,8 @@ object JdbcUtils {
} else 0
}).sum + prepStat.executeBatch().sum
} catch {
- case ex: Exception => ex.printStackTrace()
+ case ex: Exception =>
+ ex.printStackTrace()
0
} finally {
conn.commit()
@@ -124,7 +128,8 @@ object JdbcUtils {
statement = conn.createStatement
statement.executeUpdate(sql)
} catch {
- case ex: Exception => ex.printStackTrace()
+ case ex: Exception =>
+ ex.printStackTrace()
-1
} finally {
close(statement, conn)
@@ -143,7 +148,8 @@ object JdbcUtils {
stmt = createStatement(conn)
result = stmt.executeQuery(sql)
val count = result.getMetaData.getColumnCount
- if (!result.next()) Map.empty else {
+ if (!result.next()) Map.empty
+ else {
var map = Map[String, Any]()
for (x <- 1 to count) {
val key = result.getMetaData.getColumnLabel(x)
@@ -153,7 +159,8 @@ object JdbcUtils {
map
}
} catch {
- case ex: Exception => ex.printStackTrace()
+ case ex: Exception =>
+ ex.printStackTrace()
Map.empty
} finally {
close(result, stmt, conn)
@@ -177,7 +184,8 @@ object JdbcUtils {
stmt = conn.createStatement
stmt.execute(sql)
} catch {
- case ex: Exception => ex.printStackTrace()
+ case ex: Exception =>
+ ex.printStackTrace()
false
} finally {
close(stmt, conn)
@@ -220,7 +228,8 @@ object JdbcUtils {
case _ =>
}
case null =>
- throw new IllegalArgumentException(s"jdbcConfig error,property:${x._1} invalid,please see more properties jdbcConfig https://github.com/brettwooldridge/HikariCP")
+ throw new IllegalArgumentException(
+ s"jdbcConfig error,property:${x._1} invalid,please see more properties jdbcConfig https://github.com/brettwooldridge/HikariCP")
}
}
})
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/JsonUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/JsonUtils.scala
index 5e9ffbaa4..7f24728ea 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/JsonUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/JsonUtils.scala
@@ -16,13 +16,14 @@
*/
package org.apache.streampark.common.util
+import java.text.SimpleDateFormat
+
+import scala.reflect.ClassTag
+
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper, SerializationFeature}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
-import java.text.SimpleDateFormat
-import scala.reflect.ClassTag
-
object JsonUtils extends Serializable {
private val mapper = new ObjectMapper()
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/Logger.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/Logger.scala
index 4c05313b6..b6281961d 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/Logger.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/Logger.scala
@@ -16,8 +16,8 @@
*/
package org.apache.streampark.common.util
+import org.slf4j.{Logger => SlfLogger, LoggerFactory}
import org.slf4j.impl.StaticLoggerBinder
-import org.slf4j.{LoggerFactory, Logger => SlfLogger}
trait Logger {
@@ -96,4 +96,3 @@ private object Logger {
@volatile private var initialized = false
val initLock = new Object()
}
-
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/MongoConfig.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/MongoConfig.scala
index d1624ee47..78ac889c1 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/MongoConfig.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/MongoConfig.scala
@@ -16,12 +16,14 @@
*/
package org.apache.streampark.common.util
-import com.mongodb._
-import org.apache.streampark.common.conf.ConfigConst._
-
import java.util.Properties
+
import scala.collection.JavaConversions._
+import com.mongodb._
+
+import org.apache.streampark.common.conf.ConfigConst._
+
object MongoConfig {
val client_uri = "client-uri"
@@ -138,8 +140,7 @@ object MongoConfig {
val mongoCredential = MongoCredential.createScramSha1Credential(
mongoParam(username),
db,
- mongoParam(password).toCharArray
- )
+ mongoParam(password).toCharArray)
new MongoClient(serverAddresses.toList, List(mongoCredential), mongoClientOptions)
} else {
new MongoClient(serverAddresses.toList, mongoClientOptions)
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/PropertiesUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/PropertiesUtils.scala
index ee2088cbb..f56de2f31 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/PropertiesUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/PropertiesUtils.scala
@@ -16,20 +16,19 @@
*/
package org.apache.streampark.common.util
-import com.typesafe.config.ConfigFactory
-import org.yaml.snakeyaml.Yaml
-
import java.io._
+import java.util.{HashMap => JavaMap, LinkedHashMap => JavaLinkedMap, Properties, Scanner}
import java.util.concurrent.atomic.AtomicInteger
-import java.util.{Properties, Scanner, HashMap => JavaMap, LinkedHashMap => JavaLinkedMap}
+
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
import scala.collection.mutable.{Map => MutableMap}
+import com.typesafe.config.ConfigFactory
+import org.yaml.snakeyaml.Yaml
object PropertiesUtils extends Logger {
-
def readFile(filename: String): String = {
val file = new File(filename)
require(file.exists(), s"[StreamPark] readFile: file $file does not exist")
@@ -79,7 +78,8 @@ object PropertiesUtils extends Logger {
def fromHoconText(conf: String): Map[String, String] = {
require(conf != null, s"[StreamPark] fromHoconText: Hocon content must not be null")
- try parseHoconByReader(new StringReader(conf)) catch {
+ try parseHoconByReader(new StringReader(conf))
+ catch {
case e: IOException => throw new IllegalArgumentException(s"Failed when loading Hocon ", e)
}
}
@@ -189,7 +189,6 @@ object PropertiesUtils extends Logger {
def fromPropertiesFileAsJava(inputStream: InputStream): JavaMap[String, String] = new JavaMap[String, String](fromPropertiesFile(inputStream).asJava)
/**
- *
* @param file
* @return
*/
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/RedisClient.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/RedisClient.scala
index 7c3478b05..3fceed985 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/RedisClient.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/RedisClient.scala
@@ -17,16 +17,18 @@
package org.apache.streampark.common.util
-import org.apache.streampark.common.conf.ConfigConst
-import redis.clients.jedis._
-import redis.clients.jedis.exceptions.JedisConnectionException
-
import java.util.concurrent.ConcurrentHashMap
+
import scala.annotation.meta.getter
import scala.annotation.tailrec
import scala.collection.JavaConversions._
import scala.util.Random
+import redis.clients.jedis._
+import redis.clients.jedis.exceptions.JedisConnectionException
+
+import org.apache.streampark.common.conf.ConfigConst
+
object RedisClient extends Logger {
@transient
@@ -50,7 +52,8 @@ object RedisClient extends Logger {
try {
connect(endpoints(index))
} catch {
- case e: Exception => logger.error(e.getMessage)
+ case e: Exception =>
+ logger.error(e.getMessage)
connect(endpoints.drop(index))
}
}
@@ -69,8 +72,7 @@ object RedisClient extends Logger {
try {
conn = pool.getResource
} catch {
- case e: JedisConnectionException if e.getCause.toString.
- contains("ERR max number of clients reached") => {
+ case e: JedisConnectionException if e.getCause.toString.contains("ERR max number of clients reached") => {
if (sleepTime < 500) sleepTime *= 2
Thread.sleep(sleepTime)
}
@@ -114,10 +116,11 @@ object RedisClient extends Logger {
def connectCluster(res: RedisEndpoint*): JedisCluster = {
require(res.nonEmpty, "[StreamPark] The RedisEndpoint array is empty!!!")
val head = res.head
- val cluster = clusters.getOrElseUpdate(head, {
- val hostPorts = res.map(r => new HostAndPort(r.host, r.port)).toSet
- new JedisCluster(hostPorts, head.timeout, 1000, 1, head.auth, poolConfig)
- })
+ val cluster = clusters.getOrElseUpdate(
+ head, {
+ val hostPorts = res.map(r => new HostAndPort(r.host, r.port)).toSet
+ new JedisCluster(hostPorts, head.timeout, 1000, 1, head.auth, poolConfig)
+ })
cluster
}
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/RedisEndpoint.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/RedisEndpoint.scala
index 579434caf..188b49076 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/RedisEndpoint.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/RedisEndpoint.scala
@@ -17,18 +17,17 @@
package org.apache.streampark.common.util
-import org.apache.streampark.common.conf.ConfigConst._
-import redis.clients.jedis.util.{JedisClusterCRC16, JedisURIHelper, SafeEncoder}
-import redis.clients.jedis.{Jedis, Protocol}
-
import java.net.URI
import java.util.Properties
+
import scala.collection.JavaConversions._
+import redis.clients.jedis.{Jedis, Protocol}
+import redis.clients.jedis.util.{JedisClusterCRC16, JedisURIHelper, SafeEncoder}
+
+import org.apache.streampark.common.conf.ConfigConst._
+
/**
- *
- *
- *
* RedisEndpoint represents a redis connection endpoint info: host, port, auth password
* db number, and timeout
*
@@ -37,12 +36,13 @@ import scala.collection.JavaConversions._
* @param auth the authentication password
* @param db database number (should be avoided in general)
*/
-case class RedisEndpoint(host: String = Protocol.DEFAULT_HOST,
- port: Int = Protocol.DEFAULT_PORT,
- auth: String = null,
- db: Int = Protocol.DEFAULT_DATABASE,
- timeout: Int = Protocol.DEFAULT_TIMEOUT)
- extends Serializable {
+case class RedisEndpoint(
+ host: String = Protocol.DEFAULT_HOST,
+ port: Int = Protocol.DEFAULT_PORT,
+ auth: String = null,
+ db: Int = Protocol.DEFAULT_DATABASE,
+ timeout: Int = Protocol.DEFAULT_TIMEOUT)
+ extends Serializable {
/**
* Constructor from Properties. set params with redis.host, redis.port, redis.password and redis.db
@@ -55,8 +55,7 @@ case class RedisEndpoint(host: String = Protocol.DEFAULT_HOST,
conf.getOrElse(KEY_PORT, Protocol.DEFAULT_PORT).toString.toInt,
conf.getOrElse(KEY_PASSWORD, null),
conf.getOrElse(KEY_DB, Protocol.DEFAULT_DATABASE).toString.toInt,
- conf.getOrElse(KEY_TIMEOUT, Protocol.DEFAULT_TIMEOUT).toString.toInt
- )
+ conf.getOrElse(KEY_TIMEOUT, Protocol.DEFAULT_TIMEOUT).toString.toInt)
}
/**
@@ -83,11 +82,7 @@ case class RedisEndpoint(host: String = Protocol.DEFAULT_HOST,
}
-case class RedisNode(endpoint: RedisEndpoint,
- startSlot: Int,
- endSlot: Int,
- idx: Int,
- total: Int) {
+case class RedisNode(endpoint: RedisEndpoint, startSlot: Int, endSlot: Int, idx: Int, total: Int) {
def connect(): Jedis = {
endpoint.connect()
}
@@ -129,8 +124,7 @@ class RedisConfig(val initialHost: RedisEndpoint) extends Serializable {
def inter(sPos1: Int, ePos1: Int, sPos2: Int, ePos2: Int) =
if (sPos1 <= sPos2) ePos1 >= sPos2 else ePos2 >= sPos1
- nodes.filter(node => inter(sPos, ePos, node.startSlot, node.endSlot)).
- filter(_.idx == 0) //master only now
+ nodes.filter(node => inter(sPos, ePos, node.startSlot, node.endSlot)).filter(_.idx == 0) // master only now
}
/**
@@ -168,7 +162,6 @@ class RedisConfig(val initialHost: RedisEndpoint) extends Serializable {
})(0)
}
-
/**
* @param initialHost any redis endpoint of a cluster or a single server
* @return list of host nodes
@@ -193,12 +186,11 @@ class RedisConfig(val initialHost: RedisEndpoint) extends Serializable {
val host = replinfo.filter(_.contains("master_host:"))(0).trim.substring(12)
val port = replinfo.filter(_.contains("master_port:"))(0).trim.substring(12).toInt
- //simply re-enter this function witht he master host/port
- getNonClusterNodes(initialHost = RedisEndpoint(host, port,
- initialHost.auth, initialHost.db))
+ // simply re-enter this function witht he master host/port
+ getNonClusterNodes(initialHost = RedisEndpoint(host, port, initialHost.auth, initialHost.db))
} else {
- //this is a master - take its slaves
+ // this is a master - take its slaves
val slaves = replinfo.filter(x => x.contains("slave") && x.contains("online")).map(rl => {
val content = rl.substring(rl.indexOf(':') + 1).split(",")
@@ -210,9 +202,7 @@ class RedisConfig(val initialHost: RedisEndpoint) extends Serializable {
val nodes = master +: slaves
val range = nodes.length
(0 until range).map(i =>
- RedisNode(RedisEndpoint(nodes(i)._1, nodes(i)._2, initialHost.auth, initialHost.db,
- initialHost.timeout),
- 0, 16383, i, range)).toArray
+ RedisNode(RedisEndpoint(nodes(i)._1, nodes(i)._2, initialHost.auth, initialHost.db, initialHost.timeout), 0, 16383, i, range)).toArray
}
}
@@ -223,31 +213,27 @@ class RedisConfig(val initialHost: RedisEndpoint) extends Serializable {
private def getClusterNodes(initialHost: RedisEndpoint): Array[RedisNode] = {
val conn = initialHost.connect()
val res = conn.clusterSlots().flatMap {
- slotInfoObj => {
- val slotInfo = slotInfoObj.asInstanceOf[java.util.List[java.lang.Object]]
- val sPos = slotInfo.get(0).toString.toInt
- val ePos = slotInfo.get(1).toString.toInt
- /*
- * We will get all the nodes with the slots range [sPos, ePos],
- * and create RedisNode for each nodes, the total field of all
- * RedisNode are the number of the nodes whose slots range is
- * as above, and the idx field is just an index for each node
- * which will be used for adding support for slaves and so on.
- * And the idx of a master is always 0, we rely on this fact to
- * filter master.
- */
- (0 until (slotInfo.size - 2)).map(i => {
- val node = slotInfo(i + 2).asInstanceOf[java.util.List[java.lang.Object]]
- val host = SafeEncoder.encode(node.get(0).asInstanceOf[Array[scala.Byte]])
- val port = node.get(1).toString.toInt
- RedisNode(RedisEndpoint(host, port, initialHost.auth, initialHost.db,
- initialHost.timeout),
- sPos,
- ePos,
- i,
- slotInfo.size - 2)
- })
- }
+ slotInfoObj =>
+ {
+ val slotInfo = slotInfoObj.asInstanceOf[java.util.List[java.lang.Object]]
+ val sPos = slotInfo.get(0).toString.toInt
+ val ePos = slotInfo.get(1).toString.toInt
+ /*
+ * We will get all the nodes with the slots range [sPos, ePos],
+ * and create RedisNode for each nodes, the total field of all
+ * RedisNode are the number of the nodes whose slots range is
+ * as above, and the idx field is just an index for each node
+ * which will be used for adding support for slaves and so on.
+ * And the idx of a master is always 0, we rely on this fact to
+ * filter master.
+ */
+ (0 until (slotInfo.size - 2)).map(i => {
+ val node = slotInfo(i + 2).asInstanceOf[java.util.List[java.lang.Object]]
+ val host = SafeEncoder.encode(node.get(0).asInstanceOf[Array[scala.Byte]])
+ val port = node.get(1).toString.toInt
+ RedisNode(RedisEndpoint(host, port, initialHost.auth, initialHost.db, initialHost.timeout), sPos, ePos, i, slotInfo.size - 2)
+ })
+ }
}.toArray
conn.close()
res
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/RedisUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/RedisUtils.scala
index 37811203a..b88841ed5 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/RedisUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/RedisUtils.scala
@@ -16,15 +16,16 @@
*/
package org.apache.streampark.common.util
-import redis.clients.jedis.{Jedis, JedisCluster, Pipeline, ScanParams}
-
import java.lang.{Integer => JInt}
import java.util.Set
+
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
import scala.collection.immutable
import scala.util.{Failure, Success, Try}
+import redis.clients.jedis.{Jedis, JedisCluster, Pipeline, ScanParams}
+
object RedisUtils extends Logger {
def exists(key: String)(implicit endpoint: RedisEndpoint): Boolean = doRedis(_.exists(key))
@@ -39,60 +40,71 @@ object RedisUtils extends Logger {
* The Redis Setex command sets the value and expiration time. If the key already exists,
* the Setex command will replace the old value.
*/
- def setex(key: String, value: String, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): String = doRedis(_.setex(key, ttl, value), func)
+ def setex(key: String, value: String, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): String =
+ doRedis(_.setex(key, ttl, value), func)
/**
* The Redis Setnx (SET if Not eXists) command sets the specified value
* if the specified key does not exist
*/
- def setnx(key: String, value: String, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(r => {
- val x = r.setnx(key, value)
- if (x == 1 && ttl != null) {
- r.expire(key, ttl)
- }
- x
- }, func)
+ def setnx(key: String, value: String, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(
+ r => {
+ val x = r.setnx(key, value)
+ if (x == 1 && ttl != null) {
+ r.expire(key, ttl)
+ }
+ x
+ },
+ func)
/**
* The Redis Hsetnx command is used to assign values to fields in a hash table that do not exist.
* If the hash table does not exist, a new hash table is created and the HSET operation is performed.
* If the field already exists in the hash table, the operation is invalid
*/
- def hsetnx(key: String, field: String, value: String, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(r => {
- val x = r.hsetnx(key, field, value)
- if (x == 1 && ttl != null) {
- r.expire(key, ttl)
- }
- x
- }, func)
+ def hsetnx(key: String, field: String, value: String, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(
+ r => {
+ val x = r.hsetnx(key, field, value)
+ if (x == 1 && ttl != null) {
+ r.expire(key, ttl)
+ }
+ x
+ },
+ func)
def mget(keys: Array[String])(implicit endpoint: RedisEndpoint): Array[String] = doRedis(_.mget(keys: _*).asScala.toArray)
def del(key: String, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(_.del(key), func)
- def set(key: String, value: String, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): String = doRedis(r => {
- val s = r.set(key, value)
- if (ttl != null) {
- r.expire(key, ttl)
- }
- s
- }, func)
+ def set(key: String, value: String, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): String = doRedis(
+ r => {
+ val s = r.set(key, value)
+ if (ttl != null) {
+ r.expire(key, ttl)
+ }
+ s
+ },
+ func)
- def hset(key: String, field: String, value: String, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(r => {
- val s = r.hset(key, field, value)
- if (ttl != null) {
- r.expire(key, ttl)
- }
- s
- }, func)
+ def hset(key: String, field: String, value: String, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(
+ r => {
+ val s = r.hset(key, field, value)
+ if (ttl != null) {
+ r.expire(key, ttl)
+ }
+ s
+ },
+ func)
- def hmset(key: String, hash: Map[String, String], ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): String = doRedis(r => {
- val s = r.hmset(key, hash.asJava)
- if (ttl != null) {
- r.expire(key, ttl)
- }
- s
- }, func)
+ def hmset(key: String, hash: Map[String, String], ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): String = doRedis(
+ r => {
+ val s = r.hmset(key, hash.asJava)
+ if (ttl != null) {
+ r.expire(key, ttl)
+ }
+ s
+ },
+ func)
def hmget(key: String, fields: String*)(implicit endpoint: RedisEndpoint): List[String] = doRedis(_.hmget(key, fields: _*).toList)
@@ -104,119 +116,140 @@ object RedisUtils extends Logger {
}
def sadd(key: String, members: immutable.List[String], ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = {
- doRedis(r => {
- val res = r.sadd(key, members.toArray: _*)
- if (ttl != null) {
- r.expire(key, ttl)
- }
- res
- }, func)
+ doRedis(
+ r => {
+ val res = r.sadd(key, members.toArray: _*)
+ if (ttl != null) {
+ r.expire(key, ttl)
+ }
+ res
+ },
+ func)
}
def smembers(key: String)(implicit endpoint: RedisEndpoint): Set[String] = doRedis(_.smembers(key))
- def srem(key: String, members: immutable.List[String], func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(_.srem(key, members.toArray: _*), func)
+ def srem(key: String, members: immutable.List[String], func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long =
+ doRedis(_.srem(key, members.toArray: _*), func)
+
+ def getOrElseHset(key: String, field: String, value: String, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): String = doRedis(
+ x => {
+ val v = x.hget(key, field)
+ if (v == null) {
+ x.hset(key, field, value)
+ if (ttl != null) {
+ x.expire(key, ttl)
+ }
+ }
+ v
+ },
+ func)
+
+ def getOrElseSet(key: String, value: String, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): String = doRedis(
+ x => {
+ val v = x.get(key)
+ if (v == null) {
+ x.set(key, value)
+ if (ttl != null) {
+ x.expire(key, ttl)
+ }
+ }
+ v
+ },
+ func)
- def getOrElseHset(key: String, field: String, value: String, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): String = doRedis(x => {
- val v = x.hget(key, field)
- if (v == null) {
- x.hset(key, field, value)
+ def hincrBy(key: String, field: String, value: Long, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(
+ x => {
+ val reply = x.hincrBy(key, field, value)
if (ttl != null) {
x.expire(key, ttl)
}
- }
- v
- }, func)
+ reply
+ },
+ func)
- def getOrElseSet(key: String, value: String, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): String = doRedis(x => {
- val v = x.get(key)
- if (v == null) {
- x.set(key, value)
+ def hincrByFloat(key: String, field: String, value: Double, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Double = doRedis(
+ x => {
+ val reply = x.hincrByFloat(key, field, value)
if (ttl != null) {
x.expire(key, ttl)
}
- }
- v
- }, func)
-
- def hincrBy(key: String, field: String, value: Long, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(x => {
- val reply = x.hincrBy(key, field, value)
- if (ttl != null) {
- x.expire(key, ttl)
- }
- reply
- }, func)
-
- def hincrByFloat(key: String, field: String, value: Double, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Double = doRedis(x => {
- val reply = x.hincrByFloat(key, field, value)
- if (ttl != null) {
- x.expire(key, ttl)
- }
- reply
- }, func)
+ reply
+ },
+ func)
- def incrBy(key: String, value: Long, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(x => {
- val reply = x.incrBy(key, value)
- if (ttl != null) {
- x.expire(key, ttl)
- }
- reply
- }, func)
+ def incrBy(key: String, value: Long, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(
+ x => {
+ val reply = x.incrBy(key, value)
+ if (ttl != null) {
+ x.expire(key, ttl)
+ }
+ reply
+ },
+ func)
- def incrByFloat(key: String, value: Double, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Double = doRedis(x => {
- val reply = x.incrByFloat(key, value)
- if (ttl != null) {
- x.expire(key, ttl)
- }
- reply
- }, func)
+ def incrByFloat(key: String, value: Double, ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Double = doRedis(
+ x => {
+ val reply = x.incrByFloat(key, value)
+ if (ttl != null) {
+ x.expire(key, ttl)
+ }
+ reply
+ },
+ func)
/**
* Batch writing
*/
- def mSets(kvs: Seq[(String, String)], ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(x => {
- val start = System.currentTimeMillis()
- val pipe = x.pipelined()
- kvs.foreach { case (k, v) =>
- pipe.mset(k, v)
- if (ttl != null) {
- pipe.expire(k, ttl)
+ def mSets(kvs: Seq[(String, String)], ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(
+ x => {
+ val start = System.currentTimeMillis()
+ val pipe = x.pipelined()
+ kvs.foreach { case (k, v) =>
+ pipe.mset(k, v)
+ if (ttl != null) {
+ pipe.expire(k, ttl)
+ }
}
- }
- pipe.sync()
- System.currentTimeMillis() - start
- }, func)
-
- def mSetex(kvs: Seq[(String, String)], ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(x => {
- val start = System.currentTimeMillis()
- val pipe = x.pipelined()
- kvs.foreach { case (k, v) =>
- pipe.setnx(k, v)
- if (ttl != null) {
- pipe.expire(k, ttl)
+ pipe.sync()
+ System.currentTimeMillis() - start
+ },
+ func)
+
+ def mSetex(kvs: Seq[(String, String)], ttl: JInt = null, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Long = doRedis(
+ x => {
+ val start = System.currentTimeMillis()
+ val pipe = x.pipelined()
+ kvs.foreach { case (k, v) =>
+ pipe.setnx(k, v)
+ if (ttl != null) {
+ pipe.expire(k, ttl)
+ }
}
- }
- pipe.sync()
- System.currentTimeMillis() - start
- }, func)
+ pipe.sync()
+ System.currentTimeMillis() - start
+ },
+ func)
def expire(key: String, s: Int)(implicit endpoint: RedisEndpoint): Long = doRedis(_.expire(key, s))
- def delByPattern(key: String, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Any = doRedis(r => {
- // Use scan to delete 10,000 records at a time, to prevent a load of too many records, caused oom
- val scanParams = new ScanParams
- scanParams.`match`(key)
- scanParams.count(10000)
- var cursor = ScanParams.SCAN_POINTER_START
- do {
- val scanResult = r.scan(cursor, scanParams)
- cursor = scanResult.getCursor
- val keys = scanResult.getResult.toList
- if (keys.nonEmpty) {
- r.del(keys: _*)
- }
- } while (cursor != "0")
- }, func)
+ def delByPattern(key: String, func: () => Unit = null)(implicit endpoint: RedisEndpoint): Any = doRedis(
+ r => {
+ // Use scan to delete 10,000 records at a time, to prevent a load of too many records, caused oom
+ val scanParams = new ScanParams
+ scanParams.`match`(key)
+ scanParams.count(10000)
+ var cursor = ScanParams.SCAN_POINTER_START
+ do {
+ val scanResult = r.scan(cursor, scanParams)
+ cursor = scanResult.getCursor
+ val keys = scanResult.getResult.toList
+ if (keys.nonEmpty) {
+ r.del(keys: _*)
+ }
+ } while (cursor != "0")
+ },
+ func)
def hlen(key: String)(implicit endpoint: RedisEndpoint): Long = doRedis(_.hlen(key))
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/ReflectUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/ReflectUtils.scala
index 03f172281..0ec30f97d 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/ReflectUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/ReflectUtils.scala
@@ -17,12 +17,13 @@
package org.apache.streampark.common.util
-import org.apache.commons.lang3.StringUtils
-
import java.lang.reflect.{Field, Modifier}
import java.util.Objects
+
import scala.util.{Failure, Success, Try}
+import org.apache.commons.lang3.StringUtils
+
object ReflectUtils extends Logger {
/**
@@ -33,18 +34,19 @@ object ReflectUtils extends Logger {
* @return the field
* @throws SecurityException the security exception
*/
- @throws[SecurityException] def getField(beanClass: Class[_], name: String): Field = {
+ @throws[SecurityException]
+ def getField(beanClass: Class[_], name: String): Field = {
Try(beanClass.getDeclaredFields.filter(f => Objects.equals(name, f.getName)).head).getOrElse(null)
}
-
def getFieldValue(obj: Any, fieldName: String): Any = {
val field = getField(obj.getClass, fieldName)
getFieldValue(obj, field)
}
def getFieldValue(obj: Any, field: Field): Any = {
- if (Objects.isNull(obj) || Objects.isNull(field)) null else {
+ if (Objects.isNull(obj) || Objects.isNull(field)) null
+ else {
field.setAccessible(true)
field.get(obj) match {
case Success(v) => v
@@ -84,8 +86,8 @@ object ReflectUtils extends Logger {
private def makeAccessible(field: Field): Unit = {
if ((!Modifier.isPublic(field.getModifiers)
- || !Modifier.isPublic(field.getDeclaringClass.getModifiers)
- || Modifier.isFinal(field.getModifiers)) && !field.isAccessible) {
+ || !Modifier.isPublic(field.getDeclaringClass.getModifiers)
+ || Modifier.isFinal(field.getModifiers)) && !field.isAccessible) {
field.setAccessible(true)
}
}
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/SqlConvertUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/SqlConvertUtils.scala
index e61822a0d..90def5fa0 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/SqlConvertUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/SqlConvertUtils.scala
@@ -19,21 +19,19 @@ package org.apache.streampark.common.util
import java.util
import java.util.Scanner
import java.util.regex.Pattern
+
import scala.annotation.tailrec
import scala.collection.JavaConversions._
-
object SqlConvertUtils extends Logger {
private[this] val FIELD_REGEXP = Pattern.compile(
"\\s*(.*?)\\s+(([a-z]+)\\((.*?)\\)|[a-z]+)(\\s*|((.*?)(comment)\\s+(['|\"](.*?)['|\"])|(.*?))),$",
- Pattern.CASE_INSENSITIVE
- )
+ Pattern.CASE_INSENSITIVE)
private[this] val PRIMARY_REGEXP = Pattern.compile(
"primary\\s+key\\s+\\((.*?)\\)",
- Pattern.CASE_INSENSITIVE
- )
+ Pattern.CASE_INSENSITIVE)
/**
* convert to flink types
@@ -71,11 +69,11 @@ object SqlConvertUtils extends Logger {
length match {
case null => "Int32"
case x => x.trim.toInt match {
- case x if x < 3 => "Int8"
- case x if x < 5 => "Int16"
- case x if x < 9 => "Int32"
- case _ => "Int64"
- }
+ case x if x < 3 => "Int8"
+ case x if x < 5 => "Int16"
+ case x if x < 9 => "Int32"
+ case _ => "Int64"
+ }
}
case "DECIMAL" =>
length.split(",").map(_.trim.toInt) match {
@@ -91,7 +89,6 @@ object SqlConvertUtils extends Logger {
}
}
-
/**
* An magic code for format sql. only support ddl, create table syntax, etc.
*
@@ -104,9 +101,7 @@ object SqlConvertUtils extends Logger {
val COMMENT_REGEXP = Pattern.compile("(comment)\\s+(['\"])", Pattern.CASE_INSENSITIVE)
- @tailrec def commentJoin(map: util.Map[Integer, String],
- index: Integer,
- segment: String): (Integer, String) = {
+ @tailrec def commentJoin(map: util.Map[Integer, String], index: Integer, segment: String): (Integer, String) = {
val matcher = COMMENT_REGEXP.matcher(segment)
matcher.find() match {
case b if !b => index -> segment
@@ -126,9 +121,9 @@ object SqlConvertUtils extends Logger {
}
@tailrec def lengthJoin(
- map: util.Map[Integer, String],
- index: Integer,
- segment: String): (Integer, String) = {
+ map: util.Map[Integer, String],
+ index: Integer,
+ segment: String): (Integer, String) = {
LENGTH_REGEXP.findFirstIn(segment) match {
case None => commentJoin(map, index, segment)
case Some(_) =>
@@ -173,17 +168,13 @@ object SqlConvertUtils extends Logger {
}
/**
- *
* @param sql : original sql statement to be converted
* @param typeFunc : type conversion function
* @param keyFunc : handle primary key function
* @param postfix : suffix content
* @return
*/
- private[this] def convertSql(sql: String,
- typeFunc: (String, String) => String = null,
- keyFunc: String => String = null,
- postfix: String = null): String = {
+ private[this] def convertSql(sql: String, typeFunc: (String, String) => String = null, keyFunc: String => String = null, postfix: String = null): String = {
val formattedSql = formatSql(sql)
val scanner = new Scanner(formattedSql)
@@ -200,14 +191,16 @@ object SqlConvertUtils extends Logger {
}
case a if !a.startsWith("UNIQUE KEY ") && !a.startsWith("KEY ") =>
val matcher = FIELD_REGEXP.matcher(line)
- if (!matcher.find()) null; else {
+ if (!matcher.find()) null;
+ else {
val fieldName = matcher.group(1)
val dataType = (matcher.group(2), matcher.group(3)) match {
case (_, b) if b != null => b
case (a, _) => a
}
val length = matcher.group(4)
- if (dataType == null) null; else {
+ if (dataType == null) null;
+ else {
val fieldType = typeFunc(dataType, length)
matcher.group(8) match {
case x if x != null => s"$fieldName $fieldType COMMENT '${matcher.group(10)}'"
@@ -239,10 +232,8 @@ object SqlConvertUtils extends Logger {
case _ => null
}
},
- postfix
- )
+ postfix)
def mysqlToClickhouse(sql: String, postfix: String): String = convertSql(sql, toClickhouseDataType, postfix = postfix)
-
}
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/SystemPropertyUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/SystemPropertyUtils.scala
index ce1f7c94b..e784fd293 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/SystemPropertyUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/SystemPropertyUtils.scala
@@ -18,6 +18,7 @@ package org.apache.streampark.common.util
import java.io.File
import java.security.{AccessController, PrivilegedAction}
+
import scala.util.{Failure, Success, Try}
object SystemPropertyUtils extends Logger {
@@ -45,8 +46,8 @@ object SystemPropertyUtils extends Logger {
System.getSecurityManager match {
case null => System.getProperty(other)
case _ => AccessController.doPrivileged(new PrivilegedAction[String]() {
- override def run: String = System.getProperty(other)
- })
+ override def run: String = System.getProperty(other)
+ })
}
} match {
case Success(ok) =>
@@ -76,8 +77,7 @@ object SystemPropertyUtils extends Logger {
def getInt(key: String, default: Int): Int = {
Try(
- get(key).toInt
- ) match {
+ get(key).toInt) match {
case Success(ok) => ok
case Failure(_) => default
}
@@ -85,8 +85,7 @@ object SystemPropertyUtils extends Logger {
def getLong(key: String, default: Long): Long = {
Try(
- get(key).toLong
- ) match {
+ get(key).toLong) match {
case Success(ok) => ok
case Failure(_) => default
}
@@ -120,6 +119,6 @@ object SystemPropertyUtils extends Logger {
}
}
- def getTmpdir() : String = get("java.io.tmpdir", "temp")
+ def getTmpdir(): String = get("java.io.tmpdir", "temp")
}
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/ThreadUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/ThreadUtils.scala
index 29db3b16b..0d888ce49 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/ThreadUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/ThreadUtils.scala
@@ -16,14 +16,14 @@
*/
package org.apache.streampark.common.util
-import com.google.common.util.concurrent.ThreadFactoryBuilder
-
import java.util.concurrent.{ExecutorService, ThreadFactory, TimeUnit}
+import com.google.common.util.concurrent.ThreadFactoryBuilder
object ThreadUtils {
- def threadFactory(threadName: String, isDaemon: Boolean): ThreadFactory = new ThreadFactoryBuilder().setNameFormat(threadName + "-%d").setDaemon(isDaemon).build
+ def threadFactory(threadName: String, isDaemon: Boolean): ThreadFactory =
+ new ThreadFactoryBuilder().setNameFormat(threadName + "-%d").setDaemon(isDaemon).build
def threadFactory(threadName: String): ThreadFactory = threadFactory(threadName, isDaemon = true)
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 46ee90b31..5e8b34e50 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,17 +16,17 @@
*/
package org.apache.streampark.common.util
-import org.apache.commons.lang3.StringUtils
-
import java.io.{BufferedInputStream, File, FileInputStream, IOException}
import java.net.URL
+import java.util.{jar, Collection => JavaCollection, Map => JavaMap, Properties, UUID}
import java.util.jar.{JarFile, JarInputStream}
-import java.util.{Properties, UUID, jar, Collection => JavaCollection, Map => JavaMap}
+
import scala.collection.JavaConversions._
import scala.util.{Failure, Success, Try}
-object Utils {
+import org.apache.commons.lang3.StringUtils
+object Utils {
private[this] lazy val OS = System.getProperty("os.name").toLowerCase
@@ -52,7 +52,8 @@ object Utils {
}
}
- @throws[IOException] def checkJarFile(jar: URL): Unit = {
+ @throws[IOException]
+ def checkJarFile(jar: URL): Unit = {
val jarFile: File = Try(new File(jar.toURI)) match {
case Success(x) => x
case Failure(_) => throw new IOException(s"JAR file path is invalid $jar")
@@ -124,7 +125,6 @@ object Utils {
if (num1 == 0 || num2 == 0) 0.0
else (num1.toDouble / num2.toDouble * 100).formatted("%.1f").toDouble
-
def hashCode(elements: Any*): Int = {
if (elements == null) return 0
var result = 1
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/YarnUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/YarnUtils.scala
index 60f1540b6..84d01d3be 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/YarnUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/YarnUtils.scala
@@ -16,12 +16,21 @@
*/
package org.apache.streampark.common.util
-import org.apache.streampark.common.conf.{CommonConfig, InternalConfigHolder}
+import java.net.InetAddress
+import java.security.PrivilegedExceptionAction
+import java.util
+import java.util.{HashMap => JavaHashMap, List => JavaList}
+
+import scala.collection.JavaConversions._
+import scala.collection.mutable.ArrayBuffer
+import scala.util.{Failure, Success, Try}
+import scala.util.control.Breaks.{break, breakable}
+
import org.apache.commons.lang3.StringUtils
import org.apache.hadoop.fs.CommonConfigurationKeys
import org.apache.hadoop.net.NetUtils
-import org.apache.hadoop.yarn.api.records.YarnApplicationState._
import org.apache.hadoop.yarn.api.records._
+import org.apache.hadoop.yarn.api.records.YarnApplicationState._
import org.apache.hadoop.yarn.conf.{HAUtil, YarnConfiguration}
import org.apache.hadoop.yarn.util.{ConverterUtils, RMHAUtils}
import org.apache.http.client.config.RequestConfig
@@ -29,14 +38,7 @@ import org.apache.http.client.methods.HttpGet
import org.apache.http.client.protocol.HttpClientContext
import org.apache.http.impl.client.HttpClients
-import java.net.InetAddress
-import java.security.PrivilegedExceptionAction
-import java.util
-import java.util.{HashMap => JavaHashMap, List => JavaList}
-import scala.collection.JavaConversions._
-import scala.collection.mutable.ArrayBuffer
-import scala.util.control.Breaks.{break, breakable}
-import scala.util.{Failure, Success, Try}
+import org.apache.streampark.common.conf.{CommonConfig, InternalConfigHolder}
object YarnUtils extends Logger {
@@ -56,18 +58,19 @@ object YarnUtils extends Logger {
}
/**
- *
* @param appName
* @return
*/
def getAppId(appName: String): JavaList[ApplicationId] = {
val appStates = util.EnumSet.of(RUNNING, ACCEPTED, SUBMITTED)
- val appIds = try {
- HadoopUtils.yarnClient.getApplications(appStates).filter(_.getName == appName).map(_.getApplicationId)
- } catch {
- case e: Exception => e.printStackTrace()
- ArrayBuffer.empty[ApplicationId]
- }
+ val appIds =
+ try {
+ HadoopUtils.yarnClient.getApplications(appStates).filter(_.getName == appName).map(_.getApplicationId)
+ } catch {
+ case e: Exception =>
+ e.printStackTrace()
+ ArrayBuffer.empty[ApplicationId]
+ }
appIds.toList
}
@@ -79,13 +82,15 @@ object YarnUtils extends Logger {
*/
def getState(appId: String): YarnApplicationState = {
val applicationId = ConverterUtils.toApplicationId(appId)
- val state = try {
- val applicationReport = HadoopUtils.yarnClient.getApplicationReport(applicationId)
- applicationReport.getYarnApplicationState
- } catch {
- case e: Exception => e.printStackTrace()
- null
- }
+ val state =
+ try {
+ val applicationReport = HadoopUtils.yarnClient.getApplicationReport(applicationId)
+ applicationReport.getYarnApplicationState
+ } catch {
+ case e: Exception =>
+ e.printStackTrace()
+ null
+ }
state
}
@@ -129,7 +134,8 @@ object YarnUtils extends Logger {
rmHttpURL = Option(conf.get("yarn.web-proxy.address", null)) match {
case Some(proxy) => s"$protocol$proxy"
case _ =>
- val name = if (!HAUtil.isHAEnabled(conf)) addressPrefix else {
+ val name = if (!HAUtil.isHAEnabled(conf)) addressPrefix
+ else {
val yarnConf = new YarnConfiguration(conf)
val activeRMId = {
Option(RMHAUtils.findActiveRMHAId(yarnConf)) match {
@@ -154,8 +160,7 @@ object YarnUtils extends Logger {
var rmId: String = null
val rpcTimeoutForChecks = yarnConf.getInt(
CommonConfigurationKeys.HA_FC_CLI_CHECK_TIMEOUT_KEY,
- CommonConfigurationKeys.HA_FC_CLI_CHECK_TIMEOUT_DEFAULT
- )
+ CommonConfigurationKeys.HA_FC_CLI_CHECK_TIMEOUT_DEFAULT)
breakable(idUrlMap.foreach(x => {
// test yarn url
val activeUrl = httpTestYarnRMUrl(x._1, rpcTimeoutForChecks)
@@ -171,7 +176,9 @@ object YarnUtils extends Logger {
logInfo(s"current activeRMHAId: $activeRMId")
val appActiveRMKey = HAUtil.addSuffix(addressPrefix, activeRMId)
val hostnameActiveRMKey = HAUtil.addSuffix(YarnConfiguration.RM_HOSTNAME, activeRMId)
- if (null == HAUtil.getConfValueForRMInstance(appActiveRMKey, yarnConf) && null != HAUtil.getConfValueForRMInstance(hostnameActiveRMKey, yarnConf)) {
+ if (null == HAUtil.getConfValueForRMInstance(appActiveRMKey, yarnConf) && null != HAUtil.getConfValueForRMInstance(
+ hostnameActiveRMKey,
+ yarnConf)) {
logInfo(s"Find rm web address by : $hostnameActiveRMKey")
hostnameActiveRMKey
} else {
@@ -224,7 +231,6 @@ object YarnUtils extends Logger {
def getYarnAppTrackingUrl(applicationId: ApplicationId): String = HadoopUtils.yarnClient.getApplicationReport(applicationId).getTrackingUrl
/**
- *
* @param url url
* @return
*/
@@ -255,7 +261,8 @@ object YarnUtils extends Logger {
}
}
- if (url.startsWith("http://") || url.startsWith("https://")) request(url) else {
+ if (url.startsWith("http://") || url.startsWith("https://")) request(url)
+ else {
request(s"${getRMWebAppURL()}/$url")
}
}
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/ZooKeeperUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/ZooKeeperUtils.scala
index 1e4d2908b..acab0b688 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/ZooKeeperUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/ZooKeeperUtils.scala
@@ -16,15 +16,16 @@
*/
package org.apache.streampark.common.util
+import java.nio.charset.StandardCharsets
+
+import scala.collection.JavaConversions._
+import scala.collection.mutable
+
import org.apache.curator.RetryPolicy
import org.apache.curator.framework.{CuratorFramework, CuratorFrameworkFactory}
import org.apache.curator.retry.RetryNTimes
import org.apache.zookeeper.CreateMode
-import java.nio.charset.StandardCharsets
-import scala.collection.JavaConversions._
-import scala.collection.mutable
-
object ZooKeeperUtils {
private[this] val connect = "localhost:2181"
@@ -37,9 +38,9 @@ object ZooKeeperUtils {
case None =>
try {
// Set the reconnection policy ExponentialBackoffRetry, baseSleepTimeMs: initial sleep time, maxRetries: maximum number of retries, maxSleepMs: maximum retry time
- //val retryPolicy = new ExponentialBackoffRetry(10000, 5)
+ // val retryPolicy = new ExponentialBackoffRetry(10000, 5)
// (Recommended) Curator link zookeeper strategy: RetryNTimes n: the number of retries sleepMsBetweenRetries: the time between each retry
- //val retryPolicy:RetryPolicy = new RetryNTimes(3, 5000)
+ // val retryPolicy:RetryPolicy = new RetryNTimes(3, 5000)
// (Not recommended) Curator link zookeeper strategy: RetryOneTime sleepMsBetweenRetry: the time between each retry, this strategy will only be retried once
// val retryPolicy:RetryPolicy = new RetryOneTime(3000)
// Retry forever, not recommended
diff --git a/streampark-common/src/test/scala/org/apache/streampark/common/fs/LfsOperatorTest.scala b/streampark-common/src/test/scala/org/apache/streampark/common/fs/LfsOperatorTest.scala
index a99f21e6c..8960d2be1 100644
--- a/streampark-common/src/test/scala/org/apache/streampark/common/fs/LfsOperatorTest.scala
+++ b/streampark-common/src/test/scala/org/apache/streampark/common/fs/LfsOperatorTest.scala
@@ -16,16 +16,17 @@
*/
package org.apache.streampark.common.fs
+import java.io.{File, FileInputStream}
+import java.nio.file.{Files, Paths}
+
+import scala.language.implicitConversions
-import org.apache.streampark.common.fs.LfsOperatorTest.withTempDir
import org.apache.commons.codec.digest.DigestUtils
import org.apache.commons.io.{FileUtils, IOUtils}
import org.junit.jupiter.api.Assertions._
import org.junit.jupiter.api.Test
-import java.io.{File, FileInputStream}
-import java.nio.file.{Files, Paths}
-import scala.language.implicitConversions
+import org.apache.streampark.common.fs.LfsOperatorTest.withTempDir
object LfsOperatorTest {
@@ -33,8 +34,7 @@ object LfsOperatorTest {
val tempDirPath = Files.createTempDirectory("LfsOperatorTest-output")
try {
block(tempDirPath.toAbsolutePath.toString)
- }
- finally {
+ } finally {
FileUtils.deleteQuietly(tempDirPath.toFile)
}
}
@@ -56,7 +56,6 @@ class LfsOperatorTest {
}
}
-
@Test
def testExists(): Unit = withTempDir { outputDir =>
assertDoesNotThrow {
@@ -73,7 +72,6 @@ class LfsOperatorTest {
assertFalse(LfsOperator.exists(s"$outputDir/233"))
}
-
@Test
def testMkCleanDirs(): Unit = withTempDir { outputDir =>
assertDoesNotThrow {
@@ -97,7 +95,6 @@ class LfsOperatorTest {
}
}
-
@Test
def listDir(): Unit = withTempDir { outputDir =>
// list directory
@@ -120,7 +117,6 @@ class LfsOperatorTest {
assertTrue(LfsOperator.listDir(s"$outputDir/114514").isEmpty)
}
-
@Test
def testDelete(): Unit = withTempDir { outputDir =>
// delete directory
@@ -142,9 +138,9 @@ class LfsOperatorTest {
assertDoesNotThrow(LfsOperator.delete(s"$outputDir/114514"))
}
- //noinspection TypeAnnotation
+ // noinspection TypeAnnotation
val md5Hex = (f: File) => DigestUtils.md5Hex(IOUtils.toByteArray(new FileInputStream(f)))
- //noinspection TypeAnnotation
+ // noinspection TypeAnnotation
val sameFilesHex = (f1: Seq[File], f2: Seq[File]) =>
f1.map(_.getName).sorted == f2.map(_.getName).sorted && f1.map(md5Hex).sorted == f2.map(md5Hex).sorted
@@ -213,7 +209,6 @@ class LfsOperatorTest {
}
-
@Test
def testCopyDir(): Unit = withTempDir { outputDir =>
// copy dir
@@ -238,8 +233,7 @@ class LfsOperatorTest {
// copy file
assertThrows(
classOf[IllegalArgumentException],
- LfsOperator.copyDir(genRandomFile(outputDir).getAbsolutePath, s"$outputDir/out-3")
- )
+ LfsOperator.copyDir(genRandomFile(outputDir).getAbsolutePath, s"$outputDir/out-3"))
// delete or not delete the original dir
assertDoesNotThrow {
@@ -254,7 +248,6 @@ class LfsOperatorTest {
}
-
@Test
def testMove(): Unit = withTempDir { outputDir =>
// move file to directory
@@ -309,7 +302,6 @@ class LfsOperatorTest {
}
}
-
@Test
def testfileMd5(): Unit = {
assertThrows(classOf[IllegalArgumentException], LfsOperator.fileMd5(null))
@@ -317,7 +309,4 @@ class LfsOperatorTest {
assertThrows(classOf[IllegalArgumentException], LfsOperator.fileMd5("ttt/144514.dat"))
}
-
}
-
-
diff --git a/streampark-common/src/test/scala/org/apache/streampark/common/fs/package.scala b/streampark-common/src/test/scala/org/apache/streampark/common/fs/package.scala
index 46a9f5b10..00c079765 100644
--- a/streampark-common/src/test/scala/org/apache/streampark/common/fs/package.scala
+++ b/streampark-common/src/test/scala/org/apache/streampark/common/fs/package.scala
@@ -16,20 +16,20 @@
*/
package org.apache.streampark.common
-import org.apache.commons.io.FileUtils
-import org.junit.jupiter.api.function.Executable
-
import java.io.File
+
import scala.language.implicitConversions
import scala.util.Random
+import org.apache.commons.io.FileUtils
+import org.junit.jupiter.api.function.Executable
+
package object fs {
implicit def funcToExecutable[R](func: => R): Executable = new Executable() {
override def execute(): Unit = func
}
-
/**
* generate a random binary file
*
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/StreamParkConsoleBootstrap.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/StreamParkConsoleBootstrap.java
index 99be61905..55deb1720 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/StreamParkConsoleBootstrap.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/StreamParkConsoleBootstrap.java
@@ -29,6 +29,8 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import java.io.File;
/**
+ *
+ *
* <pre>
*
* _____ __ __
@@ -44,25 +46,26 @@ import java.io.File;
* [StreamPark] Make stream processing easier ô~ô!
*
* </pre>
- *
*/
@Slf4j
@SpringBootApplication
@EnableScheduling
public class StreamParkConsoleBootstrap {
- public static void main(String[] args) {
- SpringApplication application = new SpringApplication(StreamParkConsoleBootstrap.class);
- String pid = SystemPropertyUtils.get("pid");
- if (pid != null) {
- application.addListeners(new ApplicationPidFileWriter(pid));
- Runtime.getRuntime().addShutdownHook(new Thread(() -> {
- log.info("application shutdown now, pid: " + CommonUtils.getPid());
- File pidFile = new File(pid);
- pidFile.delete();
- }));
- }
- application.run();
+ public static void main(String[] args) {
+ SpringApplication application = new SpringApplication(StreamParkConsoleBootstrap.class);
+ String pid = SystemPropertyUtils.get("pid");
+ if (pid != null) {
+ application.addListeners(new ApplicationPidFileWriter(pid));
+ Runtime.getRuntime()
+ .addShutdownHook(
+ new Thread(
+ () -> {
+ log.info("application shutdown now, pid: " + CommonUtils.getPid());
+ File pidFile = new File(pid);
+ pidFile.delete();
+ }));
}
-
+ application.run();
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/AlertRestTemplateConfig.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/AlertRestTemplateConfig.java
index 1af885410..3ef1ee241 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/AlertRestTemplateConfig.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/AlertRestTemplateConfig.java
@@ -23,13 +23,13 @@ import org.springframework.web.client.RestTemplate;
@Configuration
public class AlertRestTemplateConfig {
- /**
- * Create a RestTemplate client for the alarm notification service
- *
- * @return RestTemplate
- */
- @Bean(name = "alertRestTemplate")
- public RestTemplate alertRestTemplate() {
- return new RestTemplate();
- }
+ /**
+ * Create a RestTemplate client for the alarm notification service
+ *
+ * @return RestTemplate
+ */
+ @Bean(name = "alertRestTemplate")
+ public RestTemplate alertRestTemplate() {
+ return new RestTemplate();
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/AsyncExecutorPoolConfig.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/AsyncExecutorPoolConfig.java
index 8d864a153..b50ffe289 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/AsyncExecutorPoolConfig.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/AsyncExecutorPoolConfig.java
@@ -27,17 +27,17 @@ import java.util.concurrent.ThreadPoolExecutor;
@Configuration
public class AsyncExecutorPoolConfig extends AsyncConfigurerSupport {
- @Bean
- public Executor taskExecutor() {
- ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+ @Bean
+ public Executor taskExecutor() {
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
- executor.setCorePoolSize(5);
- executor.setMaxPoolSize(20);
- executor.setQueueCapacity(100);
- executor.setKeepAliveSeconds(30);
- executor.setThreadNamePrefix("asyncTaskExecutor-");
+ executor.setCorePoolSize(5);
+ executor.setMaxPoolSize(20);
+ executor.setQueueCapacity(100);
+ executor.setKeepAliveSeconds(30);
+ executor.setThreadNamePrefix("asyncTaskExecutor-");
- executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
- return executor;
- }
+ executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+ return executor;
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/MybatisConfig.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/MybatisConfig.java
index df94e50a7..962248356 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/MybatisConfig.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/MybatisConfig.java
@@ -33,61 +33,59 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-/**
- * for MyBatis Configure management.
- */
+/** for MyBatis Configure management. */
@Configuration
@MapperScan(value = {"org.apache.streampark.console.*.mapper"})
public class MybatisConfig {
- @Bean
- public MybatisPlusInterceptor mybatisPlusInterceptor() {
- MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
- interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
- return interceptor;
- }
+ @Bean
+ public MybatisPlusInterceptor mybatisPlusInterceptor() {
+ MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
+ interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
+ return interceptor;
+ }
- /**
- * Add the plugin to the MyBatis plugin interceptor chain.
- *
- * @return {@linkplain PostgreSQLQueryInterceptor}
- */
- @Bean
- @ConditionalOnProperty(name = "spring.profiles.active", havingValue = "pgsql")
- public PostgreSQLQueryInterceptor postgreSQLQueryInterceptor() {
- return new PostgreSQLQueryInterceptor();
- }
+ /**
+ * Add the plugin to the MyBatis plugin interceptor chain.
+ *
+ * @return {@linkplain PostgreSQLQueryInterceptor}
+ */
+ @Bean
+ @ConditionalOnProperty(name = "spring.profiles.active", havingValue = "pgsql")
+ public PostgreSQLQueryInterceptor postgreSQLQueryInterceptor() {
+ return new PostgreSQLQueryInterceptor();
+ }
- /**
- * Add the plugin to the MyBatis plugin interceptor chain.
- *
- * @return {@linkplain PostgreSQLPrepareInterceptor}
- */
- @Bean
- @ConditionalOnProperty(name = "spring.profiles.active", havingValue = "pgsql")
- public PostgreSQLPrepareInterceptor postgreSQLPrepareInterceptor() {
- return new PostgreSQLPrepareInterceptor();
- }
+ /**
+ * Add the plugin to the MyBatis plugin interceptor chain.
+ *
+ * @return {@linkplain PostgreSQLPrepareInterceptor}
+ */
+ @Bean
+ @ConditionalOnProperty(name = "spring.profiles.active", havingValue = "pgsql")
+ public PostgreSQLPrepareInterceptor postgreSQLPrepareInterceptor() {
+ return new PostgreSQLPrepareInterceptor();
+ }
- /**
- * mybatis plus setting
- *
- * @return MybatisPlusPropertiesCustomizer
- */
- @Bean
- public MybatisPlusPropertiesCustomizer mybatisPlusPropertiesCustomizer() {
- return properties -> {
- properties.setTypeAliasesPackage("org.apache.streampark.console.*.entity");
- properties.setMapperLocations(new String[]{"classpath:mapper/*/*.xml"});
- MybatisConfiguration mybatisConfiguration = new MybatisConfiguration();
- mybatisConfiguration.setJdbcTypeForNull(JdbcType.NULL);
- properties.setConfiguration(mybatisConfiguration);
- GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(mybatisConfiguration);
- GlobalConfig.DbConfig dbConfig = globalConfig.getDbConfig();
- dbConfig.setIdType(IdType.AUTO);
- // close mybatis-plus banner
- globalConfig.setBanner(false);
- properties.setGlobalConfig(globalConfig);
- };
- }
+ /**
+ * mybatis plus setting
+ *
+ * @return MybatisPlusPropertiesCustomizer
+ */
+ @Bean
+ public MybatisPlusPropertiesCustomizer mybatisPlusPropertiesCustomizer() {
+ return properties -> {
+ properties.setTypeAliasesPackage("org.apache.streampark.console.*.entity");
+ properties.setMapperLocations(new String[] {"classpath:mapper/*/*.xml"});
+ MybatisConfiguration mybatisConfiguration = new MybatisConfiguration();
+ mybatisConfiguration.setJdbcTypeForNull(JdbcType.NULL);
+ properties.setConfiguration(mybatisConfiguration);
+ GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(mybatisConfiguration);
+ GlobalConfig.DbConfig dbConfig = globalConfig.getDbConfig();
+ dbConfig.setIdType(IdType.AUTO);
+ // close mybatis-plus banner
+ globalConfig.setBanner(false);
+ properties.setGlobalConfig(globalConfig);
+ };
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/P6spySqlFormatConfig.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/P6spySqlFormatConfig.java
index 5abcab705..da82ffd55 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/P6spySqlFormatConfig.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/P6spySqlFormatConfig.java
@@ -26,22 +26,22 @@ import java.time.LocalDateTime;
public class P6spySqlFormatConfig implements MessageFormattingStrategy {
- @Override
- public String formatMessage(
- int connectionId,
- String now,
- long elapsed,
- String category,
- String prepared,
- String sql,
- String url) {
+ @Override
+ public String formatMessage(
+ int connectionId,
+ String now,
+ long elapsed,
+ String category,
+ String prepared,
+ String sql,
+ String url) {
- return StringUtils.isBlank(sql) ? "" :
- String.format(
- "%s | consume %d ms | SQL statement:\n %s;",
- DateUtils.formatFullTime(LocalDateTime.now()),
- elapsed,
- sql.replaceAll("\\s+", StringUtils.SPACE)
- );
- }
+ return StringUtils.isBlank(sql)
+ ? ""
+ : String.format(
+ "%s | consume %d ms | SQL statement:\n %s;",
+ DateUtils.formatFullTime(LocalDateTime.now()),
+ elapsed,
+ sql.replaceAll("\\s+", StringUtils.SPACE));
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/SwaggerConfig.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/SwaggerConfig.java
index 27fdf36b6..3576cd9a6 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/SwaggerConfig.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/SwaggerConfig.java
@@ -60,68 +60,83 @@ import java.util.List;
@ConditionalOnWebApplication
public class SwaggerConfig implements WebMvcConfigurer {
- @Value("${swagger.enable:false}")
- private Boolean swaggerEnabled;
+ @Value("${swagger.enable:false}")
+ private Boolean swaggerEnabled;
- @Bean
- public Docket createRestApi() {
- return new Docket(DocumentationType.OAS_30)
- .enable(swaggerEnabled)
- .apiInfo(apiInfo())
- .securitySchemes(Collections.singletonList(
- HttpAuthenticationScheme.JWT_BEARER_BUILDER.name("BearerToken").build()
- ))
- .securityContexts(Collections.singletonList(
+ @Bean
+ public Docket createRestApi() {
+ return new Docket(DocumentationType.OAS_30)
+ .enable(swaggerEnabled)
+ .apiInfo(apiInfo())
+ .securitySchemes(
+ Collections.singletonList(
+ HttpAuthenticationScheme.JWT_BEARER_BUILDER.name("BearerToken").build()))
+ .securityContexts(
+ Collections.singletonList(
new SecurityContextBuilder()
- .securityReferences(Collections.singletonList(
- SecurityReference.builder()
- .scopes(new AuthorizationScope[0])
- .reference("BearerToken")
- .build()))
+ .securityReferences(
+ Collections.singletonList(
+ SecurityReference.builder()
+ .scopes(new AuthorizationScope[0])
+ .reference("BearerToken")
+ .build()))
.operationSelector(s -> true)
- .build()
- ))
- .select()
- .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
- .paths(PathSelectors.any())
- .build();
- }
+ .build()))
+ .select()
+ .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
+ .paths(PathSelectors.any())
+ .build();
+ }
- private ApiInfo apiInfo() {
- return new ApiInfoBuilder()
- .title("Apache StreamPark Api Docs")
- .description("Apache StreamPark Api Docs")
- .contact(new Contact("Apache StreamPark", "https://streampark.apache.org/", "dev@streampark.apache.org"))
- .version("2.0.0")
- .license("Apache-2.0 license")
- .build();
- }
+ private ApiInfo apiInfo() {
+ return new ApiInfoBuilder()
+ .title("Apache StreamPark Api Docs")
+ .description("Apache StreamPark Api Docs")
+ .contact(
+ new Contact(
+ "Apache StreamPark", "https://streampark.apache.org/", "dev@streampark.apache.org"))
+ .version("2.0.0")
+ .license("Apache-2.0 license")
+ .build();
+ }
- /**
- * Streampark used `ant_path_matcher` as default matching-strategy in the springboot 2.6+ version,
- * but actuator endpoint used `PathPattern` based URL matching.
- * So rewrite webEndpointServletHandlerMapping @Bean for resolve springfox and actuator conflicts.
- */
- @Bean
- public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(
- WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier,
- ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes,
- CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
- List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
- Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
- allEndpoints.addAll(webEndpoints);
- allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
- allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
- String basePath = webEndpointProperties.getBasePath();
- EndpointMapping endpointMapping = new EndpointMapping(basePath);
- boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
- return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes,
- corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath),
- shouldRegisterLinksMapping, null);
- }
-
- private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
- return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
- }
+ /**
+ * Streampark used `ant_path_matcher` as default matching-strategy in the springboot 2.6+ version,
+ * but actuator endpoint used `PathPattern` based URL matching. So rewrite
+ * webEndpointServletHandlerMapping @Bean for resolve springfox and actuator conflicts.
+ */
+ @Bean
+ public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(
+ WebEndpointsSupplier webEndpointsSupplier,
+ ServletEndpointsSupplier servletEndpointsSupplier,
+ ControllerEndpointsSupplier controllerEndpointsSupplier,
+ EndpointMediaTypes endpointMediaTypes,
+ CorsEndpointProperties corsProperties,
+ WebEndpointProperties webEndpointProperties,
+ Environment environment) {
+ List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
+ Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
+ allEndpoints.addAll(webEndpoints);
+ allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
+ allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
+ String basePath = webEndpointProperties.getBasePath();
+ EndpointMapping endpointMapping = new EndpointMapping(basePath);
+ boolean shouldRegisterLinksMapping =
+ this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
+ return new WebMvcEndpointHandlerMapping(
+ endpointMapping,
+ webEndpoints,
+ endpointMediaTypes,
+ corsProperties.toCorsConfiguration(),
+ new EndpointLinksResolver(allEndpoints, basePath),
+ shouldRegisterLinksMapping,
+ null);
+ }
+ private boolean shouldRegisterLinksMapping(
+ WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
+ return webEndpointProperties.getDiscovery().isEnabled()
+ && (StringUtils.hasText(basePath)
+ || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/WebMvcConfig.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/WebMvcConfig.java
index 2d31e5f89..6589447a5 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/WebMvcConfig.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/WebMvcConfig.java
@@ -42,47 +42,46 @@ import java.util.List;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
- @Autowired
- private FileHeaderCheckInterceptor fileHeaderCheckInterceptor;
+ @Autowired private FileHeaderCheckInterceptor fileHeaderCheckInterceptor;
- @Override
- public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
- converters.add(new ByteArrayHttpMessageConverter());
- converters.add(new StringHttpMessageConverter());
- converters.add(new ResourceHttpMessageConverter());
- converters.add(new AllEncompassingFormHttpMessageConverter());
- converters.add(jackson2HttpMessageConverter());
- }
+ @Override
+ public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
+ converters.add(new ByteArrayHttpMessageConverter());
+ converters.add(new StringHttpMessageConverter());
+ converters.add(new ResourceHttpMessageConverter());
+ converters.add(new AllEncompassingFormHttpMessageConverter());
+ converters.add(jackson2HttpMessageConverter());
+ }
- @Override
- public void addCorsMappings(CorsRegistry registry) {
- registry.addMapping("/**")
- .allowedOriginPatterns("*")
- .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
- .allowedHeaders("*")
- .allowCredentials(true)
- .maxAge(3600);
- }
+ @Override
+ public void addCorsMappings(CorsRegistry registry) {
+ registry
+ .addMapping("/**")
+ .allowedOriginPatterns("*")
+ .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
+ .allowedHeaders("*")
+ .allowCredentials(true)
+ .maxAge(3600);
+ }
- @Bean
- public MappingJackson2HttpMessageConverter jackson2HttpMessageConverter() {
- MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
- ObjectMapper mapper = new ObjectMapper();
+ @Bean
+ public MappingJackson2HttpMessageConverter jackson2HttpMessageConverter() {
+ MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
+ ObjectMapper mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
- SimpleModule simpleModule = new SimpleModule();
- simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
- simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
- mapper.registerModule(simpleModule);
- converter.setObjectMapper(mapper);
- return converter;
- }
+ SimpleModule simpleModule = new SimpleModule();
+ simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
+ simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
+ mapper.registerModule(simpleModule);
+ converter.setObjectMapper(mapper);
+ return converter;
+ }
- @Override
- public void addInterceptors(InterceptorRegistry registry) {
- registry.addInterceptor(fileHeaderCheckInterceptor)
- .addPathPatterns("/flink/app/upload");
- }
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(fileHeaderCheckInterceptor).addPathPatterns("/flink/app/upload");
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/WebSocketConfig.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/WebSocketConfig.java
index 81e0446f1..8fa4dc53a 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/WebSocketConfig.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/WebSocketConfig.java
@@ -23,8 +23,8 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter;
@Configuration
public class WebSocketConfig {
- @Bean
- public ServerEndpointExporter serverEndpointExporter() {
- return new ServerEndpointExporter();
- }
+ @Bean
+ public ServerEndpointExporter serverEndpointExporter() {
+ return new ServerEndpointExporter();
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/ApiDocConstant.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/ApiDocConstant.java
index 152286109..31220f862 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/ApiDocConstant.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/ApiDocConstant.java
@@ -19,6 +19,5 @@ package org.apache.streampark.console.base.domain;
public class ApiDocConstant {
- public static final String FLINK_APP_OP_TAG = "FLINK_APPLICATION_OPERATION_TAG";
-
+ public static final String FLINK_APP_OP_TAG = "FLINK_APPLICATION_OPERATION_TAG";
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/Constant.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/Constant.java
index 1bc8a7f84..34baf6f08 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/Constant.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/Constant.java
@@ -19,18 +19,17 @@ package org.apache.streampark.console.base.domain;
public class Constant {
- // token cache prefix
- public static final String TOKEN_CACHE_PREFIX = "streampark.cache.token.";
- // order rules: descend
- public static final String ORDER_DESC = "desc";
- // order rules: ascend
- public static final String ORDER_ASC = "asc";
- public static final String DEFAULT_SORT_FIELD = "create_time";
- // button
- public static final String TYPE_BUTTON = "1";
- // menu
- public static final String TYPE_MENU = "0";
- public static final String APP_MENU_ID = "100015";
- public static final String APP_DETAIL_MENU_ID = "100018";
-
+ // token cache prefix
+ public static final String TOKEN_CACHE_PREFIX = "streampark.cache.token.";
+ // order rules: descend
+ public static final String ORDER_DESC = "desc";
+ // order rules: ascend
+ public static final String ORDER_ASC = "asc";
+ public static final String DEFAULT_SORT_FIELD = "create_time";
+ // button
+ public static final String TYPE_BUTTON = "1";
+ // menu
+ public static final String TYPE_MENU = "0";
+ public static final String APP_MENU_ID = "100015";
+ public static final String APP_DETAIL_MENU_ID = "100018";
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/ResponseCode.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/ResponseCode.java
index cc3b0385d..65ce33c9c 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/ResponseCode.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/ResponseCode.java
@@ -19,13 +19,13 @@ package org.apache.streampark.console.base.domain;
public interface ResponseCode {
- Long CODE_SUCCESS = 200L;
+ Long CODE_SUCCESS = 200L;
- Long CODE_FAIL = 500L;
+ Long CODE_FAIL = 500L;
- Long CODE_FORBIDDEN = 403L;
+ Long CODE_FORBIDDEN = 403L;
- Long CODE_FAIL_ALERT = 501L;
+ Long CODE_FAIL_ALERT = 501L;
- Long CODE_FAIL_DETAIL = 502L;
+ Long CODE_FAIL_DETAIL = 502L;
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestRequest.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestRequest.java
index a05b8d1d4..15eb62383 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestRequest.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestRequest.java
@@ -24,11 +24,11 @@ import java.io.Serializable;
@Data
public class RestRequest implements Serializable {
- private static final long serialVersionUID = -4869594085374385813L;
+ private static final long serialVersionUID = -4869594085374385813L;
- private int pageSize = 10;
- private int pageNum = 1;
+ private int pageSize = 10;
+ private int pageNum = 1;
- private String sortField;
- private String sortOrder;
+ private String sortField;
+ private String sortOrder;
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestResponse.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestResponse.java
index 61d7b79b4..f15fdc410 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestResponse.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestResponse.java
@@ -21,48 +21,48 @@ import java.util.HashMap;
public class RestResponse extends HashMap<String, Object> {
- public static final String STATUS_SUCCESS = "success";
- public static final String STATUS_FAIL = "error";
+ public static final String STATUS_SUCCESS = "success";
+ public static final String STATUS_FAIL = "error";
- private static final long serialVersionUID = -8713837118340960775L;
+ private static final long serialVersionUID = -8713837118340960775L;
- public static RestResponse success(Object data) {
- RestResponse resp = new RestResponse();
- resp.put("status", STATUS_SUCCESS);
- resp.put("code", ResponseCode.CODE_SUCCESS);
- resp.put("data", data);
- return resp;
- }
+ public static RestResponse success(Object data) {
+ RestResponse resp = new RestResponse();
+ resp.put("status", STATUS_SUCCESS);
+ resp.put("code", ResponseCode.CODE_SUCCESS);
+ resp.put("data", data);
+ return resp;
+ }
- public static RestResponse success() {
- RestResponse resp = new RestResponse();
- resp.put("status", STATUS_SUCCESS);
- resp.put("code", ResponseCode.CODE_SUCCESS);
- return resp;
- }
+ public static RestResponse success() {
+ RestResponse resp = new RestResponse();
+ resp.put("status", STATUS_SUCCESS);
+ resp.put("code", ResponseCode.CODE_SUCCESS);
+ return resp;
+ }
- public static RestResponse fail(String message, Long code) {
- RestResponse resp = new RestResponse();
- resp.put("status", STATUS_FAIL);
- resp.put("message", message);
- resp.put("code", code);
- resp.put("data", null);
- return resp;
- }
+ public static RestResponse fail(String message, Long code) {
+ RestResponse resp = new RestResponse();
+ resp.put("status", STATUS_FAIL);
+ resp.put("message", message);
+ resp.put("code", code);
+ resp.put("data", null);
+ return resp;
+ }
- public RestResponse message(String message) {
- this.put("message", message);
- return this;
- }
+ public RestResponse message(String message) {
+ this.put("message", message);
+ return this;
+ }
- public RestResponse data(Object data) {
- this.put("data", data);
- return this;
- }
+ public RestResponse data(Object data) {
+ this.put("data", data);
+ return this;
+ }
- @Override
- public RestResponse put(String key, Object value) {
- super.put(key, value);
- return this;
- }
+ @Override
+ public RestResponse put(String key, Object value) {
+ super.put(key, value);
+ return this;
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/router/RouterMeta.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/router/RouterMeta.java
index a2f44125e..5753b6f64 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/router/RouterMeta.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/router/RouterMeta.java
@@ -23,22 +23,19 @@ import lombok.Data;
import java.io.Serializable;
-/**
- * Vue Router Meta
- *
- */
+/** Vue Router Meta */
@Data
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RouterMeta implements Serializable {
- private static final long serialVersionUID = 5499925008927195914L;
+ private static final long serialVersionUID = 5499925008927195914L;
- private Boolean closeable;
+ private Boolean closeable;
- private Boolean hidden;
+ private Boolean hidden;
- private Boolean keepAlive;
+ private Boolean keepAlive;
- private String icon;
+ private String icon;
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/router/RouterTree.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/router/RouterTree.java
index 521c1dadf..4ef671e9b 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/router/RouterTree.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/router/RouterTree.java
@@ -30,63 +30,62 @@ import java.util.List;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RouterTree<T> {
- private String id;
+ private String id;
- private String key;
+ private String key;
- private String icon;
+ private String icon;
- private String title;
+ private String title;
- private String value;
+ private String value;
- private String text;
+ private String text;
- private String permission;
+ private String permission;
- private String type;
+ private String type;
- private boolean display;
+ private boolean display;
- private Double order;
+ private Double order;
- private String path;
+ private String path;
- private String component;
+ private String component;
- private List<RouterTree<T>> children;
+ private List<RouterTree<T>> children;
- private String parentId;
+ private String parentId;
- private boolean hasParent = false;
+ private boolean hasParent = false;
- private boolean hasChildren = false;
+ private boolean hasChildren = false;
- private Date createTime;
+ private Date createTime;
- private Date modifyTime;
+ private Date modifyTime;
- public void initChildren() {
- this.children = new ArrayList<>();
- }
+ public void initChildren() {
+ this.children = new ArrayList<>();
+ }
- public RouterTree() {}
-
- public RouterTree(Menu menu) {
- this.setId(menu.getMenuId().toString());
- this.setKey(this.getId());
- this.setParentId(menu.getParentId().toString());
- this.setText(menu.getMenuName());
- this.setTitle(menu.getMenuName());
- this.setIcon(menu.getIcon());
- this.setComponent(menu.getComponent());
- this.setCreateTime(menu.getCreateTime());
- this.setModifyTime(menu.getModifyTime());
- this.setPath(menu.getPath());
- this.setOrder(menu.getOrderNum());
- this.setPermission(menu.getPerms());
- this.setType(menu.getType());
- this.setDisplay(menu.isDisplay());
- }
+ public RouterTree() {}
+ public RouterTree(Menu menu) {
+ this.setId(menu.getMenuId().toString());
+ this.setKey(this.getId());
+ this.setParentId(menu.getParentId().toString());
+ this.setText(menu.getMenuName());
+ this.setTitle(menu.getMenuName());
+ this.setIcon(menu.getIcon());
+ this.setComponent(menu.getComponent());
+ this.setCreateTime(menu.getCreateTime());
+ this.setModifyTime(menu.getModifyTime());
+ this.setPath(menu.getPath());
+ this.setOrder(menu.getOrderNum());
+ this.setPermission(menu.getPerms());
+ this.setType(menu.getType());
+ this.setDisplay(menu.isDisplay());
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/router/VueRouter.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/router/VueRouter.java
index 7bcd07be1..45688413c 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/router/VueRouter.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/router/VueRouter.java
@@ -25,40 +25,34 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-/**
- * Build Vue Router
- */
+/** Build Vue Router */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class VueRouter<T> implements Serializable {
- private static final long serialVersionUID = -3327478146308500708L;
+ private static final long serialVersionUID = -3327478146308500708L;
- @JsonIgnore
- private String id;
+ @JsonIgnore private String id;
- @JsonIgnore
- private String parentId;
+ @JsonIgnore private String parentId;
- private String path;
+ private String path;
- private String name;
+ private String name;
- private String component;
+ private String component;
- private String redirect;
+ private String redirect;
- private RouterMeta meta;
+ private RouterMeta meta;
- private List<VueRouter<T>> children;
+ private List<VueRouter<T>> children;
- @JsonIgnore
- private boolean hasParent = false;
+ @JsonIgnore private boolean hasParent = false;
- @JsonIgnore
- private boolean hasChildren = false;
+ @JsonIgnore private boolean hasChildren = false;
- public void initChildren() {
- this.children = new ArrayList<>();
- }
+ public void initChildren() {
+ this.children = new ArrayList<>();
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/enums/FileType.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/enums/FileType.java
index 5fca50b23..2ad8760ad 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/enums/FileType.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/enums/FileType.java
@@ -19,24 +19,22 @@ package org.apache.streampark.console.base.enums;
public enum FileType {
- /**
- * JAR Archive
- */
- JAR("JAR", "504B0304");
+ /** JAR Archive */
+ JAR("JAR", "504B0304");
- private final String alias;
- private final String magicNumber;
+ private final String alias;
+ private final String magicNumber;
- FileType(String alias, String magicNumber) {
- this.alias = alias;
- this.magicNumber = magicNumber;
- }
+ FileType(String alias, String magicNumber) {
+ this.alias = alias;
+ this.magicNumber = magicNumber;
+ }
- public String getAlias() {
- return alias;
- }
+ public String getAlias() {
+ return alias;
+ }
- public String getMagicNumber() {
- return magicNumber;
- }
+ public String getMagicNumber() {
+ return magicNumber;
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/AbstractApiException.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/AbstractApiException.java
index a9cbc33c4..0d602bbdc 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/AbstractApiException.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/AbstractApiException.java
@@ -18,31 +18,32 @@
package org.apache.streampark.console.base.exception;
/**
+ *
+ *
* <pre>
* An exception message that needs to be notified to front-end.
* </pre>
*/
public abstract class AbstractApiException extends RuntimeException {
- private final long responseCode;
-
- protected AbstractApiException(String message, long responseCode) {
- super(message);
- this.responseCode = responseCode;
- }
+ private final long responseCode;
- protected AbstractApiException(Throwable cause, long responseCode) {
- super(cause);
- this.responseCode = responseCode;
- }
+ protected AbstractApiException(String message, long responseCode) {
+ super(message);
+ this.responseCode = responseCode;
+ }
- protected AbstractApiException(String message, Throwable cause, long responseCode) {
- super(message, cause);
- this.responseCode = responseCode;
- }
+ protected AbstractApiException(Throwable cause, long responseCode) {
+ super(cause);
+ this.responseCode = responseCode;
+ }
- public long getResponseCode() {
- return responseCode;
- }
+ protected AbstractApiException(String message, Throwable cause, long responseCode) {
+ super(message, cause);
+ this.responseCode = responseCode;
+ }
+ public long getResponseCode() {
+ return responseCode;
+ }
}
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 4a761a58f..812ebed4e 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
@@ -20,15 +20,15 @@ package org.apache.streampark.console.base.exception;
import org.apache.streampark.common.util.ExceptionUtils;
public class AlertException extends ApiAlertException {
- public AlertException(String message) {
- super(message);
- }
+ public AlertException(String message) {
+ super(message);
+ }
- public AlertException(Throwable cause) {
- super(ExceptionUtils.stringifyException(cause));
- }
+ public AlertException(Throwable cause) {
+ super(ExceptionUtils.stringifyException(cause));
+ }
- public AlertException(String message, Throwable cause) {
- super(message, cause);
- }
+ public AlertException(String message, Throwable cause) {
+ super(message, cause);
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApiAlertException.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApiAlertException.java
index 1f2a21db9..a1ec2816c 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApiAlertException.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApiAlertException.java
@@ -20,6 +20,8 @@ package org.apache.streampark.console.base.exception;
import org.apache.streampark.console.base.domain.ResponseCode;
/**
+ *
+ *
* <pre>
* An exception message that needs to be notified to front-end,
* usually a <strong>simple</strong>, clear</strong> message, e.g:
@@ -30,16 +32,15 @@ import org.apache.streampark.console.base.domain.ResponseCode;
*/
public class ApiAlertException extends AbstractApiException {
- public ApiAlertException(String message) {
- super(message, ResponseCode.CODE_FAIL_ALERT);
- }
-
- public ApiAlertException(Throwable cause) {
- super(cause, ResponseCode.CODE_FAIL_ALERT);
- }
+ public ApiAlertException(String message) {
+ super(message, ResponseCode.CODE_FAIL_ALERT);
+ }
- public ApiAlertException(String message, Throwable cause) {
- super(message, cause, ResponseCode.CODE_FAIL_ALERT);
- }
+ public ApiAlertException(Throwable cause) {
+ super(cause, ResponseCode.CODE_FAIL_ALERT);
+ }
+ public ApiAlertException(String message, Throwable cause) {
+ super(message, cause, ResponseCode.CODE_FAIL_ALERT);
+ }
}
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 d54a6de44..5adbd8c72 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
@@ -21,6 +21,8 @@ import org.apache.streampark.common.util.ExceptionUtils;
import org.apache.streampark.console.base.domain.ResponseCode;
/**
+ *
+ *
* <pre>
* An exception message that needs to be notified to front-end,
* is a detailed exception message,such as the stackTrace info,
@@ -30,20 +32,20 @@ import org.apache.streampark.console.base.domain.ResponseCode;
*/
public class ApiDetailException extends AbstractApiException {
- public ApiDetailException(String message) {
- super(message, ResponseCode.CODE_FAIL_DETAIL);
- }
+ public ApiDetailException(String message) {
+ super(message, ResponseCode.CODE_FAIL_DETAIL);
+ }
- public ApiDetailException(Throwable cause) {
- super(ExceptionUtils.stringifyException(cause), ResponseCode.CODE_FAIL_DETAIL);
- }
+ public ApiDetailException(Throwable cause) {
+ super(ExceptionUtils.stringifyException(cause), ResponseCode.CODE_FAIL_DETAIL);
+ }
- public ApiDetailException(String message, Throwable cause) {
- super(message + ExceptionUtils.stringifyException(cause), ResponseCode.CODE_FAIL_DETAIL);
- }
+ public ApiDetailException(String message, Throwable cause) {
+ super(message + ExceptionUtils.stringifyException(cause), ResponseCode.CODE_FAIL_DETAIL);
+ }
- @Override
- public String getMessage() {
- return "Detail exception: \n" + super.getMessage();
- }
+ @Override
+ public String getMessage() {
+ return "Detail exception: \n" + super.getMessage();
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApplicationException.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApplicationException.java
index c3e22ff8a..cb59f558f 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApplicationException.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/ApplicationException.java
@@ -18,12 +18,11 @@
package org.apache.streampark.console.base.exception;
public class ApplicationException extends ApiAlertException {
- public ApplicationException(String message) {
- super(message);
- }
+ public ApplicationException(String message) {
+ super(message);
+ }
- public ApplicationException(Throwable cause) {
- super(cause.getMessage());
- }
+ public ApplicationException(Throwable cause) {
+ super(cause.getMessage());
+ }
}
-
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/IllegalFileTypeException.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/IllegalFileTypeException.java
index 6bb3fbdf4..531d3f1e1 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/IllegalFileTypeException.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/IllegalFileTypeException.java
@@ -18,11 +18,11 @@
package org.apache.streampark.console.base.exception;
public class IllegalFileTypeException extends ApiAlertException {
- public IllegalFileTypeException(String message) {
- super(message);
- }
+ public IllegalFileTypeException(String message) {
+ super(message);
+ }
- public IllegalFileTypeException(String message, Throwable cause) {
- super(message, cause);
- }
+ public IllegalFileTypeException(String message, Throwable cause) {
+ super(message, cause);
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/InternalException.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/InternalException.java
index b8f0cfdaa..021fc1c45 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/InternalException.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/exception/InternalException.java
@@ -17,16 +17,14 @@
package org.apache.streampark.console.base.exception;
-/**
- * System Internal Exception
- */
+/** System Internal Exception */
public class InternalException extends Exception {
- public InternalException(String message) {
- super(message);
- }
+ public InternalException(String message) {
+ super(message);
+ }
- public InternalException(String message, Throwable cause) {
- super(message, cause);
- }
+ public InternalException(String message, Throwable cause) {
+ super(message, cause);
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/handler/GlobalExceptionHandler.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/handler/GlobalExceptionHandler.java
index 685f09c61..91b13c3a7 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/handler/GlobalExceptionHandler.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/handler/GlobalExceptionHandler.java
@@ -47,69 +47,70 @@ import java.util.Set;
@Order(value = Ordered.HIGHEST_PRECEDENCE)
public class GlobalExceptionHandler {
- @ExceptionHandler(value = Exception.class)
- @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
- public RestResponse handleException(Exception e) {
- log.info("Internal server error:", e);
- return RestResponse.fail("internal server error: " + e.getMessage(), ResponseCode.CODE_FAIL);
- }
+ @ExceptionHandler(value = Exception.class)
+ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
+ public RestResponse handleException(Exception e) {
+ log.info("Internal server error:", e);
+ return RestResponse.fail("internal server error: " + e.getMessage(), ResponseCode.CODE_FAIL);
+ }
- @ExceptionHandler(value = HttpRequestMethodNotSupportedException.class)
- @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
- public RestResponse handleException(HttpRequestMethodNotSupportedException e) {
- log.info("not supported request method,exception:{}", e.getMessage());
- return RestResponse.fail("not supported request method,exception:" + e.getMessage(), ResponseCode.CODE_FAIL);
- }
+ @ExceptionHandler(value = HttpRequestMethodNotSupportedException.class)
+ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
+ public RestResponse handleException(HttpRequestMethodNotSupportedException e) {
+ log.info("not supported request method,exception:{}", e.getMessage());
+ return RestResponse.fail(
+ "not supported request method,exception:" + e.getMessage(), ResponseCode.CODE_FAIL);
+ }
- @ExceptionHandler(value = AbstractApiException.class)
- @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
- public RestResponse handleException(AbstractApiException e) {
- log.info("api exception:{}", e.getMessage());
- return RestResponse.fail(e.getMessage(), e.getResponseCode());
- }
+ @ExceptionHandler(value = AbstractApiException.class)
+ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
+ public RestResponse handleException(AbstractApiException e) {
+ log.info("api exception:{}", e.getMessage());
+ return RestResponse.fail(e.getMessage(), e.getResponseCode());
+ }
-
- /**
- * Unified processing of request parameter verification (entity object parameter transfer)
- *
- * @param e BindException
- * @return RestResponse
- */
- @ExceptionHandler(BindException.class)
- @ResponseStatus(HttpStatus.BAD_REQUEST)
- public RestResponse validExceptionHandler(BindException e) {
- StringBuilder message = new StringBuilder();
- List<FieldError> fieldErrors = e.getBindingResult().getFieldErrors();
- for (FieldError error : fieldErrors) {
- message.append(error.getField()).append(error.getDefaultMessage()).append(StringPool.COMMA);
- }
- message = new StringBuilder(message.substring(0, message.length() - 1));
- return RestResponse.fail(message.toString(), ResponseCode.CODE_FAIL);
+ /**
+ * Unified processing of request parameter verification (entity object parameter transfer)
+ *
+ * @param e BindException
+ * @return RestResponse
+ */
+ @ExceptionHandler(BindException.class)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
+ public RestResponse validExceptionHandler(BindException e) {
+ StringBuilder message = new StringBuilder();
+ List<FieldError> fieldErrors = e.getBindingResult().getFieldErrors();
+ for (FieldError error : fieldErrors) {
+ message.append(error.getField()).append(error.getDefaultMessage()).append(StringPool.COMMA);
}
+ message = new StringBuilder(message.substring(0, message.length() - 1));
+ return RestResponse.fail(message.toString(), ResponseCode.CODE_FAIL);
+ }
- /**
- * Unified processing of request parameter verification (ordinary parameter transfer)
- *
- * @param e ConstraintViolationException
- * @return RestResponse
- */
- @ExceptionHandler(value = ConstraintViolationException.class)
- @ResponseStatus(HttpStatus.BAD_REQUEST)
- public RestResponse handleConstraintViolationException(ConstraintViolationException e) {
- StringBuilder message = new StringBuilder();
- Set<ConstraintViolation<?>> violations = e.getConstraintViolations();
- for (ConstraintViolation<?> violation : violations) {
- Path path = violation.getPropertyPath();
- String[] pathArr = StringUtils.splitByWholeSeparatorPreserveAllTokens(path.toString(), StringPool.DOT);
- message.append(pathArr[1]).append(violation.getMessage()).append(StringPool.COMMA);
- }
- message = new StringBuilder(message.substring(0, message.length() - 1));
- return RestResponse.fail(message.toString(), ResponseCode.CODE_FAIL);
+ /**
+ * Unified processing of request parameter verification (ordinary parameter transfer)
+ *
+ * @param e ConstraintViolationException
+ * @return RestResponse
+ */
+ @ExceptionHandler(value = ConstraintViolationException.class)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
+ public RestResponse handleConstraintViolationException(ConstraintViolationException e) {
+ StringBuilder message = new StringBuilder();
+ Set<ConstraintViolation<?>> violations = e.getConstraintViolations();
+ for (ConstraintViolation<?> violation : violations) {
+ Path path = violation.getPropertyPath();
+ String[] pathArr =
+ StringUtils.splitByWholeSeparatorPreserveAllTokens(path.toString(), StringPool.DOT);
+ message.append(pathArr[1]).append(violation.getMessage()).append(StringPool.COMMA);
}
+ message = new StringBuilder(message.substring(0, message.length() - 1));
+ return RestResponse.fail(message.toString(), ResponseCode.CODE_FAIL);
+ }
- @ExceptionHandler(value = UnauthorizedException.class)
- @ResponseStatus(HttpStatus.FORBIDDEN)
- public void handleUnauthorizedException(Exception e) {
- log.info("Permission denied,{}", e.getMessage());
- }
+ @ExceptionHandler(value = UnauthorizedException.class)
+ @ResponseStatus(HttpStatus.FORBIDDEN)
+ public void handleUnauthorizedException(Exception e) {
+ log.info("Permission denied,{}", e.getMessage());
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/interceptor/FileHeaderCheckInterceptor.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/interceptor/FileHeaderCheckInterceptor.java
index 882ff56bb..99630283a 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/interceptor/FileHeaderCheckInterceptor.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/interceptor/FileHeaderCheckInterceptor.java
@@ -37,57 +37,65 @@ import java.util.Map;
@Component
public class FileHeaderCheckInterceptor implements HandlerInterceptor {
- private static final List<String> FILE_HEADERS = new ArrayList<>();
- private static final int HEADER_LENGTH = 8;
+ private static final List<String> FILE_HEADERS = new ArrayList<>();
+ private static final int HEADER_LENGTH = 8;
- static {
- FILE_HEADERS.add(FileType.JAR.getMagicNumber());
- }
+ static {
+ FILE_HEADERS.add(FileType.JAR.getMagicNumber());
+ }
- @Override
- public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
- if (request != null && request instanceof MultipartHttpServletRequest) {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- Map<String, MultipartFile> files = multipartRequest.getFileMap();
- Iterator<String> iterator = files.keySet().iterator();
- while (iterator.hasNext()) {
- String formKey = iterator.next();
- MultipartFile multipartFile = multipartRequest.getFile(formKey);
- byte[] file = multipartFile.getBytes();
- if (file.length > HEADER_LENGTH) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < HEADER_LENGTH; i++) {
- int v = file[i] & 0xFF;
- String hv = Integer.toHexString(v);
- if (hv.length() < 2) {
- sb.append(0);
- }
- sb.append(hv);
- }
- boolean isFound = false;
- String fileHead = sb.toString().toUpperCase();
- for (String header : FILE_HEADERS) {
- if (fileHead.startsWith(header)) {
- isFound = true;
- break;
- }
- }
- if (!isFound) {
- throw new IllegalFileTypeException("Illegal file type, please check");
- }
- }
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
+ throws Exception {
+ if (request != null && request instanceof MultipartHttpServletRequest) {
+ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+ Map<String, MultipartFile> files = multipartRequest.getFileMap();
+ Iterator<String> iterator = files.keySet().iterator();
+ while (iterator.hasNext()) {
+ String formKey = iterator.next();
+ MultipartFile multipartFile = multipartRequest.getFile(formKey);
+ byte[] file = multipartFile.getBytes();
+ if (file.length > HEADER_LENGTH) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < HEADER_LENGTH; i++) {
+ int v = file[i] & 0xFF;
+ String hv = Integer.toHexString(v);
+ if (hv.length() < 2) {
+ sb.append(0);
+ }
+ sb.append(hv);
+ }
+ boolean isFound = false;
+ String fileHead = sb.toString().toUpperCase();
+ for (String header : FILE_HEADERS) {
+ if (fileHead.startsWith(header)) {
+ isFound = true;
+ break;
}
+ }
+ if (!isFound) {
+ throw new IllegalFileTypeException("Illegal file type, please check");
+ }
}
- return true;
+ }
}
+ return true;
+ }
- @Override
- public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
- HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
- }
+ @Override
+ public void postHandle(
+ HttpServletRequest request,
+ HttpServletResponse response,
+ Object handler,
+ ModelAndView modelAndView)
+ throws Exception {
+ HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
+ }
- @Override
- public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
- HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
- }
+ @Override
+ public void afterCompletion(
+ HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
+ throws Exception {
+ HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/mybatis/interceptor/PostgreSQLPrepareInterceptor.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/mybatis/interceptor/PostgreSQLPrepareInterceptor.java
index 2f112b437..ccb79bb4b 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/mybatis/interceptor/PostgreSQLPrepareInterceptor.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/mybatis/interceptor/PostgreSQLPrepareInterceptor.java
@@ -29,30 +29,29 @@ import java.lang.reflect.Field;
import java.sql.Connection;
import java.util.Properties;
-/**
- * the mybatis interceptor for update/insert/delete.
- */
+/** the mybatis interceptor for update/insert/delete. */
@Intercepts({
- @Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})
+ @Signature(
+ type = StatementHandler.class,
+ method = "prepare",
+ args = {Connection.class, Integer.class})
})
public class PostgreSQLPrepareInterceptor implements Interceptor {
- @Override
- public Object intercept(final Invocation invocation) throws Throwable {
- StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
- BoundSql boundSql = statementHandler.getBoundSql();
- Field field = boundSql.getClass().getDeclaredField("sql");
- field.setAccessible(true);
- field.set(boundSql, boundSql.getSql().replace("`", "\"").toLowerCase());
- return invocation.proceed();
- }
-
- @Override
- public Object plugin(final Object target) {
- return Plugin.wrap(target, this);
- }
+ @Override
+ public Object intercept(final Invocation invocation) throws Throwable {
+ StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
+ BoundSql boundSql = statementHandler.getBoundSql();
+ Field field = boundSql.getClass().getDeclaredField("sql");
+ field.setAccessible(true);
+ field.set(boundSql, boundSql.getSql().replace("`", "\"").toLowerCase());
+ return invocation.proceed();
+ }
- @Override
- public void setProperties(final Properties properties) {
+ @Override
+ public Object plugin(final Object target) {
+ return Plugin.wrap(target, this);
+ }
- }
+ @Override
+ public void setProperties(final Properties properties) {}
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/mybatis/interceptor/PostgreSQLQueryInterceptor.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/mybatis/interceptor/PostgreSQLQueryInterceptor.java
index 3c284fb0e..80a8ce678 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/mybatis/interceptor/PostgreSQLQueryInterceptor.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/mybatis/interceptor/PostgreSQLQueryInterceptor.java
@@ -32,56 +32,53 @@ import org.apache.ibatis.session.RowBounds;
import java.util.Properties;
/**
- * The limit syntax of PostgreSQL conflicts with that of MySQL,
- * So use the interceptor to process the SQL syntax here.
+ * The limit syntax of PostgreSQL conflicts with that of MySQL, So use the interceptor to process
+ * the SQL syntax here.
*/
@Intercepts({
- @Signature(
- type = Executor.class, method = "query",
- args = {
- MappedStatement.class,
- Object.class,
- RowBounds.class,
- ResultHandler.class
- }),
- @Signature(
- type = Executor.class,
- method = "query",
- args = {
- MappedStatement.class,
- Object.class,
- RowBounds.class,
- ResultHandler.class, CacheKey.class,
- BoundSql.class})
+ @Signature(
+ type = Executor.class,
+ method = "query",
+ args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
+ @Signature(
+ type = Executor.class,
+ method = "query",
+ args = {
+ MappedStatement.class,
+ Object.class,
+ RowBounds.class,
+ ResultHandler.class,
+ CacheKey.class,
+ BoundSql.class
+ })
})
public class PostgreSQLQueryInterceptor implements Interceptor {
- @Override
- public Object intercept(final Invocation invocation) throws Throwable {
- Object[] args = invocation.getArgs();
- MappedStatement ms = (MappedStatement) args[0];
- Object parameter = args[1];
- RowBounds rowBounds = (RowBounds) args[2];
- ResultHandler<?> resultHandler = (ResultHandler<?>) args[3];
- Executor executor = (Executor) invocation.getTarget();
- CacheKey cacheKey;
- BoundSql boundSql;
- if (args.length == 4) {
- boundSql = ms.getBoundSql(parameter);
- cacheKey = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
- } else {
- cacheKey = (CacheKey) args[4];
- boundSql = (BoundSql) args[5];
- }
- return executor.query(ms, parameter, rowBounds, resultHandler, cacheKey, boundSql);
+ @Override
+ public Object intercept(final Invocation invocation) throws Throwable {
+ Object[] args = invocation.getArgs();
+ MappedStatement ms = (MappedStatement) args[0];
+ Object parameter = args[1];
+ RowBounds rowBounds = (RowBounds) args[2];
+ ResultHandler<?> resultHandler = (ResultHandler<?>) args[3];
+ Executor executor = (Executor) invocation.getTarget();
+ CacheKey cacheKey;
+ BoundSql boundSql;
+ if (args.length == 4) {
+ boundSql = ms.getBoundSql(parameter);
+ cacheKey = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
+ } else {
+ cacheKey = (CacheKey) args[4];
+ boundSql = (BoundSql) args[5];
}
+ return executor.query(ms, parameter, rowBounds, resultHandler, cacheKey, boundSql);
+ }
- @Override
- public Object plugin(final Object target) {
- return Plugin.wrap(target, this);
- }
+ @Override
+ public Object plugin(final Object target) {
+ return Plugin.wrap(target, this);
+ }
- @Override
- public void setProperties(final Properties properties) {
- }
+ @Override
+ public void setProperties(final Properties properties) {}
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/mybatis/pager/MybatisPager.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/mybatis/pager/MybatisPager.java
index 5adede711..8f7906444 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/mybatis/pager/MybatisPager.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/mybatis/pager/MybatisPager.java
@@ -31,37 +31,36 @@ import java.util.List;
@SuppressWarnings("unchecked")
public final class MybatisPager<T> {
- public Page<T> getDefaultPage(RestRequest request) {
- return getPage(request, Constant.DEFAULT_SORT_FIELD, Constant.ORDER_DESC);
- }
+ public Page<T> getDefaultPage(RestRequest request) {
+ return getPage(request, Constant.DEFAULT_SORT_FIELD, Constant.ORDER_DESC);
+ }
- public Page<T> getPage(RestRequest request, String defaultSort, String defaultOrder) {
- Page<T> page = new Page<>();
- page.setCurrent(request.getPageNum());
- page.setSize(request.getPageSize());
+ public Page<T> getPage(RestRequest request, String defaultSort, String defaultOrder) {
+ Page<T> page = new Page<>();
+ page.setCurrent(request.getPageNum());
+ page.setSize(request.getPageSize());
- List<OrderItem> orderItems = new ArrayList<>(0);
- if (StringUtils.isNotBlank(request.getSortField())
- && StringUtils.isNotBlank(request.getSortOrder())) {
- String sortField = WebUtils.camelToUnderscore(request.getSortField());
- if (StringUtils.equals(request.getSortOrder(), Constant.ORDER_DESC)) {
- orderItems.add(OrderItem.desc(sortField));
- } else {
- orderItems.add(OrderItem.asc(sortField));
- }
+ List<OrderItem> orderItems = new ArrayList<>(0);
+ if (StringUtils.isNotBlank(request.getSortField())
+ && StringUtils.isNotBlank(request.getSortOrder())) {
+ String sortField = WebUtils.camelToUnderscore(request.getSortField());
+ if (StringUtils.equals(request.getSortOrder(), Constant.ORDER_DESC)) {
+ orderItems.add(OrderItem.desc(sortField));
+ } else {
+ orderItems.add(OrderItem.asc(sortField));
+ }
+ } else {
+ if (StringUtils.isNotBlank(defaultSort)) {
+ if (StringUtils.equals(defaultOrder, Constant.ORDER_DESC)) {
+ orderItems.add(OrderItem.desc(defaultSort));
} else {
- if (StringUtils.isNotBlank(defaultSort)) {
- if (StringUtils.equals(defaultOrder, Constant.ORDER_DESC)) {
- orderItems.add(OrderItem.desc(defaultSort));
- } else {
- orderItems.add(OrderItem.asc(defaultSort));
- }
- }
- }
- if (!orderItems.isEmpty()) {
- page.setOrders(orderItems);
+ orderItems.add(OrderItem.asc(defaultSort));
}
- return page;
+ }
}
-
+ if (!orderItems.isEmpty()) {
+ page.setOrders(orderItems);
+ }
+ return page;
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/properties/ShiroProperties.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/properties/ShiroProperties.java
index 54ff83b42..4a9d9f42c 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/properties/ShiroProperties.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/properties/ShiroProperties.java
@@ -26,11 +26,8 @@ import org.springframework.context.annotation.Configuration;
@ConfigurationProperties(prefix = "streampark.shiro")
public class ShiroProperties {
- private String anonUrl;
-
- /**
- * token default effective time: 1d
- */
- private Long jwtTimeOut = 86400L;
+ private String anonUrl;
+ /** token default effective time: 1d */
+ private Long jwtTimeOut = 86400L;
}
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 996a9251f..c6c52bc33 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.AssertUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cglib.beans.BeanMap;
@@ -45,605 +45,601 @@ import java.util.UUID;
@Slf4j
public final class CommonUtils implements Serializable {
- private CommonUtils() {
+ private CommonUtils() {}
- }
-
- private static final long serialVersionUID = 6458428317155311192L;
+ private static final long serialVersionUID = 6458428317155311192L;
- private static final String OS = System.getProperty("os.name").toLowerCase();
+ private static final String OS = System.getProperty("os.name").toLowerCase();
- /**
- * is empty
- *
- * @param objs handle obj
- * @return Boolean
- * @see <b>Returns true if the object is Null, returns true if the size of the collection is 0,
- * and returns true if the iterator has no next</b>
- * @since 1.0
- */
- public static Boolean isEmpty(Object... objs) {
-
- if (objs == null) {
- return Boolean.TRUE;
- }
+ /**
+ * is empty
+ *
+ * @param objs handle obj
+ * @return Boolean
+ * @see <b>Returns true if the object is Null, returns true if the size of the collection is 0,
+ * and returns true if the iterator has no next</b>
+ * @since 1.0
+ */
+ public static Boolean isEmpty(Object... objs) {
- if (objs.length == 0) {
- return Boolean.TRUE;
- }
-
- for (Object obj : objs) {
- if (obj == null) {
- return true;
- }
-
- // char sequence
- if ((obj instanceof CharSequence) && "".equals(obj.toString().trim())) {
- return true;
- }
- // collection
- if (obj instanceof Collection) {
- if (((Collection<?>) obj).isEmpty()) {
- return true;
- }
- }
- // map
- if (obj instanceof Map) {
- if (((Map<?, ?>) obj).isEmpty()) {
- return true;
- }
- }
-
- if (obj instanceof Iterable) {
- if (((Iterable<?>) obj).iterator() == null || !((Iterable<?>) obj).iterator().hasNext()) {
- return true;
- }
- }
-
- // iterator
- if (obj instanceof Iterator) {
- if (!((Iterator<?>) obj).hasNext()) {
- return true;
- }
- }
-
- // file
- if (obj instanceof File) {
- if (!((File) obj).exists()) {
- return true;
- }
- }
-
- if ((obj instanceof Object[]) && ((Object[]) obj).length == 0) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * non-empty
- *
- * @param obj handle obj
- * @return Boolean
- * @since 1.0
- */
- public static Boolean notEmpty(Object... obj) {
- return !isEmpty(obj);
+ if (objs == null) {
+ return Boolean.TRUE;
}
- public static Long toLong(Object val, Long defVal) {
- if (isEmpty(val)) {
- return defVal;
- }
- try {
- return Long.parseLong(val.toString());
- } catch (NumberFormatException e) {
- return defVal;
- }
+ if (objs.length == 0) {
+ return Boolean.TRUE;
}
- public static Long toLong(Object val) {
- return toLong(val, null);
- }
+ for (Object obj : objs) {
+ if (obj == null) {
+ return true;
+ }
- public static Integer toInt(Object val, Integer defVal) {
- if (isEmpty(val)) {
- return defVal;
+ // char sequence
+ if ((obj instanceof CharSequence) && "".equals(obj.toString().trim())) {
+ return true;
+ }
+ // collection
+ if (obj instanceof Collection) {
+ if (((Collection<?>) obj).isEmpty()) {
+ return true;
}
- try {
- return Integer.parseInt(val.toString());
- } catch (NumberFormatException e) {
- return defVal;
+ }
+ // map
+ if (obj instanceof Map) {
+ if (((Map<?, ?>) obj).isEmpty()) {
+ return true;
}
- }
+ }
- public static float toFloat(Object val, float defVal) {
- if (isEmpty(val)) {
- return defVal;
- }
- try {
- return Float.parseFloat(val.toString());
- } catch (NumberFormatException e) {
- return defVal;
+ if (obj instanceof Iterable) {
+ if (((Iterable<?>) obj).iterator() == null || !((Iterable<?>) obj).iterator().hasNext()) {
+ return true;
}
- }
+ }
- public static Boolean toBoolean(String text, Boolean defVal) {
- if (isEmpty(text)) {
- return false;
- }
- try {
- return Boolean.parseBoolean(text);
- } catch (NumberFormatException e) {
- return defVal;
+ // iterator
+ if (obj instanceof Iterator) {
+ if (!((Iterator<?>) obj).hasNext()) {
+ return true;
}
- }
-
- public static Boolean toBoolean(String text) {
- return toBoolean(text, false);
- }
-
- public static Integer toInt(Object val) {
- return toInt(val, null);
- }
-
- public static Float toFloat(Object val) {
- return toFloat(val, 0f);
- }
-
- public static List arrayToList(Object source) {
- return Arrays.asList(ObjectUtils.toObjectArray(source));
- }
+ }
- public static boolean contains(Iterator iterator, Object element) {
- if (iterator != null) {
- while (iterator.hasNext()) {
- Object candidate = iterator.next();
- if (ObjectUtils.safeEquals(candidate, element)) {
- return true;
- }
- }
+ // file
+ if (obj instanceof File) {
+ if (!((File) obj).exists()) {
+ return true;
}
- return false;
- }
-
- /**
- * Check whether the given Enumeration contains the given element.
- *
- * @param enumeration the Enumeration to check
- * @param element the element to look for
- * @return <code>true</code> if found, <code>false</code> else
- */
- public static boolean contains(Enumeration enumeration, Object element) {
- if (enumeration != null) {
- while (enumeration.hasMoreElements()) {
- Object candidate = enumeration.nextElement();
- if (ObjectUtils.safeEquals(candidate, element)) {
- return true;
- }
- }
- }
- return false;
- }
+ }
- public static boolean deleteFile(File dir) {
- if (!dir.exists()) {
- return false;
- }
- if (dir.isDirectory()) {
- for (File file : dir.listFiles()) {
- if (!deleteFile(file)) {
- return false;
- }
- }
- }
- return dir.delete();
- }
-
- /**
- * Check whether the given Collection contains the given element instance.
- *
- * <p>Enforces the given instance to be present, rather than returning <code>true</code> for an
- * equal element as well.
- *
- * @param collection the Collection to check
- * @param element the element to look for
- * @return <code>true</code> if found, <code>false</code> else
- */
- public static boolean containsInstance(Collection collection, Object element) {
- if (collection != null) {
- for (Object candidate : collection) {
- if (candidate == element) {
- return true;
- }
- }
- }
- return false;
+ if ((obj instanceof Object[]) && ((Object[]) obj).length == 0) {
+ return true;
+ }
}
- public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) {
- ArrayList<A> elements = new ArrayList<A>();
- while (enumeration.hasMoreElements()) {
- elements.add(enumeration.nextElement());
- }
- return elements.toArray(array);
- }
-
- /**
- * Adapt an enumeration to an iterator.
- *
- * @param enumeration the enumeration
- * @return the iterator
- */
- public static <E> Iterator<E> toIterator(Enumeration<E> enumeration) {
- @SuppressWarnings("hiding")
- class EnumerationIterator<E> implements Iterator<E> {
- private final Enumeration<E> enumeration;
-
- public EnumerationIterator(Enumeration<E> enumeration) {
- this.enumeration = enumeration;
- }
-
- @Override
- public boolean hasNext() {
- return this.enumeration.hasMoreElements();
- }
-
- @Override
- public E next() {
- return this.enumeration.nextElement();
- }
-
- @Override
- public void remove() throws UnsupportedOperationException {
- throw new UnsupportedOperationException("Not supported");
- }
- }
+ return false;
+ }
+
+ /**
+ * non-empty
+ *
+ * @param obj handle obj
+ * @return Boolean
+ * @since 1.0
+ */
+ public static Boolean notEmpty(Object... obj) {
+ return !isEmpty(obj);
+ }
- return new EnumerationIterator<E>(enumeration);
+ public static Long toLong(Object val, Long defVal) {
+ if (isEmpty(val)) {
+ return defVal;
}
-
- public static String getOsName() {
- return OS;
+ try {
+ return Long.parseLong(val.toString());
+ } catch (NumberFormatException e) {
+ return defVal;
}
+ }
- public static boolean isLinux() {
- return OS.indexOf("linux") >= 0;
- }
+ public static Long toLong(Object val) {
+ return toLong(val, null);
+ }
+
+ public static Integer toInt(Object val, Integer defVal) {
+ if (isEmpty(val)) {
+ return defVal;
+ }
+ try {
+ return Integer.parseInt(val.toString());
+ } catch (NumberFormatException e) {
+ return defVal;
+ }
+ }
+
+ public static float toFloat(Object val, float defVal) {
+ if (isEmpty(val)) {
+ return defVal;
+ }
+ try {
+ return Float.parseFloat(val.toString());
+ } catch (NumberFormatException e) {
+ return defVal;
+ }
+ }
+
+ public static Boolean toBoolean(String text, Boolean defVal) {
+ if (isEmpty(text)) {
+ return false;
+ }
+ try {
+ return Boolean.parseBoolean(text);
+ } catch (NumberFormatException e) {
+ return defVal;
+ }
+ }
+
+ public static Boolean toBoolean(String text) {
+ return toBoolean(text, false);
+ }
+
+ public static Integer toInt(Object val) {
+ return toInt(val, null);
+ }
+
+ public static Float toFloat(Object val) {
+ return toFloat(val, 0f);
+ }
+
+ public static List arrayToList(Object source) {
+ return Arrays.asList(ObjectUtils.toObjectArray(source));
+ }
+
+ public static boolean contains(Iterator iterator, Object element) {
+ if (iterator != null) {
+ while (iterator.hasNext()) {
+ Object candidate = iterator.next();
+ if (ObjectUtils.safeEquals(candidate, element)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Check whether the given Enumeration contains the given element.
+ *
+ * @param enumeration the Enumeration to check
+ * @param element the element to look for
+ * @return <code>true</code> if found, <code>false</code> else
+ */
+ public static boolean contains(Enumeration enumeration, Object element) {
+ if (enumeration != null) {
+ while (enumeration.hasMoreElements()) {
+ Object candidate = enumeration.nextElement();
+ if (ObjectUtils.safeEquals(candidate, element)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean deleteFile(File dir) {
+ if (!dir.exists()) {
+ return false;
+ }
+ if (dir.isDirectory()) {
+ for (File file : dir.listFiles()) {
+ if (!deleteFile(file)) {
+ return false;
+ }
+ }
+ }
+ return dir.delete();
+ }
+
+ /**
+ * Check whether the given Collection contains the given element instance.
+ *
+ * <p>Enforces the given instance to be present, rather than returning <code>true</code> for an
+ * equal element as well.
+ *
+ * @param collection the Collection to check
+ * @param element the element to look for
+ * @return <code>true</code> if found, <code>false</code> else
+ */
+ public static boolean containsInstance(Collection collection, Object element) {
+ if (collection != null) {
+ for (Object candidate : collection) {
+ if (candidate == element) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) {
+ ArrayList<A> elements = new ArrayList<A>();
+ while (enumeration.hasMoreElements()) {
+ elements.add(enumeration.nextElement());
+ }
+ return elements.toArray(array);
+ }
+
+ /**
+ * Adapt an enumeration to an iterator.
+ *
+ * @param enumeration the enumeration
+ * @return the iterator
+ */
+ public static <E> Iterator<E> toIterator(Enumeration<E> enumeration) {
+ @SuppressWarnings("hiding")
+ class EnumerationIterator<E> implements Iterator<E> {
+ private final Enumeration<E> enumeration;
+
+ public EnumerationIterator(Enumeration<E> enumeration) {
+ this.enumeration = enumeration;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return this.enumeration.hasMoreElements();
+ }
+
+ @Override
+ public E next() {
+ return this.enumeration.nextElement();
+ }
+
+ @Override
+ public void remove() throws UnsupportedOperationException {
+ throw new UnsupportedOperationException("Not supported");
+ }
+ }
+
+ return new EnumerationIterator<E>(enumeration);
+ }
+
+ public static String getOsName() {
+ return OS;
+ }
+
+ public static boolean isLinux() {
+ return OS.indexOf("linux") >= 0;
+ }
+
+ public static boolean isMacOS() {
+ return OS.indexOf("mac") >= 0 && OS.indexOf("os") > 0 && OS.indexOf("x") < 0;
+ }
+
+ public static boolean isMacOSX() {
+ return OS.indexOf("mac") >= 0 && OS.indexOf("os") > 0 && OS.indexOf("x") > 0;
+ }
- public static boolean isMacOS() {
- return OS.indexOf("mac") >= 0 && OS.indexOf("os") > 0 && OS.indexOf("x") < 0;
- }
+ public static boolean isWindows() {
+ return OS.indexOf("windows") >= 0;
+ }
- public static boolean isMacOSX() {
- return OS.indexOf("mac") >= 0 && OS.indexOf("os") > 0 && OS.indexOf("x") > 0;
- }
+ public static boolean isOS2() {
+ return OS.indexOf("os/2") >= 0;
+ }
- public static boolean isWindows() {
- return OS.indexOf("windows") >= 0;
- }
+ public static boolean isSolaris() {
+ return OS.indexOf("solaris") >= 0;
+ }
- public static boolean isOS2() {
- return OS.indexOf("os/2") >= 0;
- }
+ public static boolean isSunOS() {
+ return OS.indexOf("sunos") >= 0;
+ }
- public static boolean isSolaris() {
- return OS.indexOf("solaris") >= 0;
- }
+ public static boolean isMPEiX() {
+ return OS.indexOf("mpe/ix") >= 0;
+ }
- public static boolean isSunOS() {
- return OS.indexOf("sunos") >= 0;
- }
+ public static boolean isHPUX() {
+ return OS.indexOf("hp-ux") >= 0;
+ }
- public static boolean isMPEiX() {
- return OS.indexOf("mpe/ix") >= 0;
- }
+ public static boolean isAix() {
+ return OS.indexOf("aix") >= 0;
+ }
- public static boolean isHPUX() {
- return OS.indexOf("hp-ux") >= 0;
- }
+ public static boolean isOS390() {
+ return OS.indexOf("os/390") >= 0;
+ }
- public static boolean isAix() {
- return OS.indexOf("aix") >= 0;
- }
+ public static boolean isFreeBSD() {
+ return OS.indexOf("freebsd") >= 0;
+ }
- public static boolean isOS390() {
- return OS.indexOf("os/390") >= 0;
- }
+ public static boolean isIrix() {
+ return OS.indexOf("irix") >= 0;
+ }
- public static boolean isFreeBSD() {
- return OS.indexOf("freebsd") >= 0;
- }
+ public static boolean isDigitalUnix() {
+ return OS.indexOf("digital") >= 0 && OS.indexOf("unix") > 0;
+ }
- public static boolean isIrix() {
- return OS.indexOf("irix") >= 0;
- }
+ public static boolean isNetWare() {
+ return OS.indexOf("netware") >= 0;
+ }
- public static boolean isDigitalUnix() {
- return OS.indexOf("digital") >= 0 && OS.indexOf("unix") > 0;
- }
+ public static boolean isOSF1() {
+ return OS.indexOf("osf1") >= 0;
+ }
- public static boolean isNetWare() {
- return OS.indexOf("netware") >= 0;
- }
+ public static boolean isOpenVMS() {
+ return OS.indexOf("openvms") >= 0;
+ }
- public static boolean isOSF1() {
- return OS.indexOf("osf1") >= 0;
+ public static boolean isUnix() {
+ boolean isUnix = isLinux();
+ if (!isUnix) {
+ isUnix = isMacOS();
}
-
- public static boolean isOpenVMS() {
- return OS.indexOf("openvms") >= 0;
+ if (!isUnix) {
+ isUnix = isMacOSX();
}
-
- public static boolean isUnix() {
- boolean isUnix = isLinux();
- if (!isUnix) {
- isUnix = isMacOS();
- }
- if (!isUnix) {
- isUnix = isMacOSX();
- }
- if (!isUnix) {
- isUnix = isLinux();
- }
- if (!isUnix) {
- isUnix = isDigitalUnix();
- }
- if (!isUnix) {
- isUnix = isAix();
- }
- if (!isUnix) {
- isUnix = isFreeBSD();
- }
- if (!isUnix) {
- isUnix = isHPUX();
- }
- if (!isUnix) {
- isUnix = isIrix();
- }
- if (!isUnix) {
- isUnix = isMPEiX();
- }
- if (!isUnix) {
- isUnix = isNetWare();
- }
- if (!isUnix) {
- isUnix = isOpenVMS();
- }
- if (!isUnix) {
- isUnix = isOS2();
- }
- if (!isUnix) {
- isUnix = isOS390();
- }
- if (!isUnix) {
- isUnix = isOSF1();
- }
- if (!isUnix) {
- isUnix = isSunOS();
- }
- if (!isUnix) {
- isUnix = isSolaris();
- }
- return isUnix;
+ if (!isUnix) {
+ isUnix = isLinux();
}
-
- /**
- * linux kernel platform 1 window: 2 other platforms 0
- */
- public static int getPlatform() {
- int platform = 0;
- if (CommonUtils.isUnix()) {
- platform = 1;
- }
- if (CommonUtils.isWindows()) {
- platform = 2;
- }
- return platform;
+ if (!isUnix) {
+ isUnix = isDigitalUnix();
}
-
- public static <K, V extends Comparable<? super V>> Map<K, V> sortMapByValue(Map<K, V> map) {
- List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet());
- Collections.sort(list, Comparator.comparing(Map.Entry::getValue));
- Map<K, V> result = new LinkedHashMap<>();
- for (Map.Entry<K, V> entry : list) {
- result.put(entry.getKey(), entry.getValue());
- }
- return result;
+ if (!isUnix) {
+ isUnix = isAix();
}
-
- public static <T> T[] arrayRemoveElements(T[] array, T... elem) {
- AssertUtils.notNull(array);
- List<T> arrayList = new ArrayList<>(0);
- Collections.addAll(arrayList, array);
- if (isEmpty(elem)) {
- return array;
- }
- for (T el : elem) {
- arrayList.remove(el);
- }
- return Arrays.copyOf(arrayList.toArray(array), arrayList.size());
+ if (!isUnix) {
+ isUnix = isFreeBSD();
}
-
- public static <T> T[] arrayRemoveIndex(T[] array, int... index) {
- AssertUtils.notNull(array);
- for (int j : index) {
- if (j < 0 || j > array.length - 1) {
- throw new IndexOutOfBoundsException("index error.@" + j);
- }
- }
- List<T> arrayList = new ArrayList<>(0);
- Collections.addAll(arrayList, array);
- int i = 0;
- for (int j : index) {
- arrayList.remove(j - i);
- ++i;
- }
- return Arrays.copyOf(arrayList.toArray(array), arrayList.size());
- }
-
- public static <T> T[] arrayInsertIndex(T[] array, int index, T t) {
- AssertUtils.notNull(array);
- List<T> arrayList = new ArrayList<T>(array.length + 1);
- if (index == 0) {
- arrayList.add(t);
- Collections.addAll(arrayList, array);
-
- } else {
- T[] before = Arrays.copyOfRange(array, 0, index);
- T[] after = Arrays.copyOfRange(array, index, array.length);
- Collections.addAll(arrayList, before);
- arrayList.add(t);
- Collections.addAll(arrayList, after);
- }
- return arrayList.toArray(array);
+ if (!isUnix) {
+ isUnix = isHPUX();
}
-
- public static String uuid() {
- return UUID.randomUUID().toString().replaceAll("-", "");
+ if (!isUnix) {
+ isUnix = isIrix();
}
-
- /**
- * generate specific length uuid
- *
- * @param len len
- * @return uuid
- */
- public static String uuid(int len) {
- StringBuffer sb = new StringBuffer();
- while (sb.length() < len) {
- sb.append(uuid());
- }
- return sb.toString().substring(0, len);
+ if (!isUnix) {
+ isUnix = isMPEiX();
}
-
- public static Double fixedNum(Number number) {
- return fixedNum(number, 2);
- }
-
- public static Double fixedNum(Number number, int offset) {
- if (number.doubleValue() == 0.00) {
- return 0D;
- }
- String prefix = "";
- while (offset > 0) {
- prefix += "0";
- offset -= 1;
- }
-
- java.text.DecimalFormat df = new java.text.DecimalFormat("#." + prefix);
- try {
- return Double.parseDouble(df.format(number));
- } catch (NumberFormatException e) {
- log.error(e.getMessage(), e);
- return 0.0;
- }
- }
-
- public static String toPercent(Number number) {
- return toPercent(number, 0);
+ if (!isUnix) {
+ isUnix = isNetWare();
}
-
- public static String toPercent(Number number, int offset) {
- offset += 2;
- Double num = fixedNum(number, offset);
- return (num * 100) + "%";
- }
-
- /**
- * convert bean to map
- *
- * @param bean bean
- * @return map
- */
- public static <T> Map<String, Object> beanToMap(T bean) {
- Map<String, Object> map = new HashMap<>();
- if (bean != null) {
- BeanMap beanMap = BeanMap.create(bean);
- for (Object key : beanMap.keySet()) {
- map.put(key + "", beanMap.get(key));
- }
- }
- return map;
- }
-
- /**
- * convert map to bean
- *
- * @param map map
- * @param bean bean class
- * @return bean
- */
- public static <T> T mapToBean(Map<String, Object> map, T bean) {
- BeanMap beanMap = BeanMap.create(bean);
- beanMap.putAll(map);
- return bean;
- }
-
- /**
- * convert List<T> to List<Map<String, Object>>
- *
- * @param objList
- * @return
- * @throws IOException
- */
- public static <T> List<Map<String, Object>> objectsToMaps(List<T> objList) {
- List<Map<String, Object>> list = new ArrayList<>();
- if (objList != null && objList.size() > 0) {
- Map<String, Object> map = null;
- T bean = null;
- for (T t : objList) {
- bean = t;
- map = beanToMap(bean);
- list.add(map);
- }
- }
- return list;
- }
-
- /**
- * convert List<Map<String,Object>> to List<T>
- *
- * @param maps maps
- * @param clazz element class
- * @return
- * @throws InstantiationException
- * @throws IllegalAccessException
- */
- public static <T> List<T> mapsToObjects(List<Map<String, Object>> maps, Class<T> clazz)
- throws InstantiationException, IllegalAccessException {
- List<T> list = new ArrayList<>();
- if (maps != null && maps.size() > 0) {
- Map<String, Object> map;
- T bean;
- for (Map<String, Object> stringObjectMap : maps) {
- map = stringObjectMap;
- bean = clazz.newInstance();
- mapToBean(map, bean);
- list.add(bean);
- }
- }
- return list;
- }
-
- public static Integer getPid() {
- RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
- String name = runtime.getName();
- try {
- return Integer.parseInt(name.substring(0, name.indexOf('@')));
- } catch (Exception e) {
- return -1;
- }
- }
-
- public static boolean isLegalUrl(String url) {
- try {
- new URI(url);
- return true;
- } catch (Exception ignored) {
- return false;
- }
+ if (!isUnix) {
+ isUnix = isOpenVMS();
+ }
+ if (!isUnix) {
+ isUnix = isOS2();
+ }
+ if (!isUnix) {
+ isUnix = isOS390();
+ }
+ if (!isUnix) {
+ isUnix = isOSF1();
}
+ if (!isUnix) {
+ isUnix = isSunOS();
+ }
+ if (!isUnix) {
+ isUnix = isSolaris();
+ }
+ return isUnix;
+ }
+
+ /** linux kernel platform 1 window: 2 other platforms 0 */
+ public static int getPlatform() {
+ int platform = 0;
+ if (CommonUtils.isUnix()) {
+ platform = 1;
+ }
+ if (CommonUtils.isWindows()) {
+ platform = 2;
+ }
+ return platform;
+ }
+
+ public static <K, V extends Comparable<? super V>> Map<K, V> sortMapByValue(Map<K, V> map) {
+ List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet());
+ Collections.sort(list, Comparator.comparing(Map.Entry::getValue));
+ Map<K, V> result = new LinkedHashMap<>();
+ for (Map.Entry<K, V> entry : list) {
+ result.put(entry.getKey(), entry.getValue());
+ }
+ return result;
+ }
+
+ public static <T> T[] arrayRemoveElements(T[] array, T... elem) {
+ AssertUtils.notNull(array);
+ List<T> arrayList = new ArrayList<>(0);
+ Collections.addAll(arrayList, array);
+ if (isEmpty(elem)) {
+ return array;
+ }
+ for (T el : elem) {
+ arrayList.remove(el);
+ }
+ return Arrays.copyOf(arrayList.toArray(array), arrayList.size());
+ }
+
+ public static <T> T[] arrayRemoveIndex(T[] array, int... index) {
+ AssertUtils.notNull(array);
+ for (int j : index) {
+ if (j < 0 || j > array.length - 1) {
+ throw new IndexOutOfBoundsException("index error.@" + j);
+ }
+ }
+ List<T> arrayList = new ArrayList<>(0);
+ Collections.addAll(arrayList, array);
+ int i = 0;
+ for (int j : index) {
+ arrayList.remove(j - i);
+ ++i;
+ }
+ return Arrays.copyOf(arrayList.toArray(array), arrayList.size());
+ }
+
+ public static <T> T[] arrayInsertIndex(T[] array, int index, T t) {
+ AssertUtils.notNull(array);
+ List<T> arrayList = new ArrayList<T>(array.length + 1);
+ if (index == 0) {
+ arrayList.add(t);
+ Collections.addAll(arrayList, array);
+
+ } else {
+ T[] before = Arrays.copyOfRange(array, 0, index);
+ T[] after = Arrays.copyOfRange(array, index, array.length);
+ Collections.addAll(arrayList, before);
+ arrayList.add(t);
+ Collections.addAll(arrayList, after);
+ }
+ return arrayList.toArray(array);
+ }
+
+ public static String uuid() {
+ return UUID.randomUUID().toString().replaceAll("-", "");
+ }
+
+ /**
+ * generate specific length uuid
+ *
+ * @param len len
+ * @return uuid
+ */
+ public static String uuid(int len) {
+ StringBuffer sb = new StringBuffer();
+ while (sb.length() < len) {
+ sb.append(uuid());
+ }
+ return sb.toString().substring(0, len);
+ }
+
+ public static Double fixedNum(Number number) {
+ return fixedNum(number, 2);
+ }
+
+ public static Double fixedNum(Number number, int offset) {
+ if (number.doubleValue() == 0.00) {
+ return 0D;
+ }
+ String prefix = "";
+ while (offset > 0) {
+ prefix += "0";
+ offset -= 1;
+ }
+
+ java.text.DecimalFormat df = new java.text.DecimalFormat("#." + prefix);
+ try {
+ return Double.parseDouble(df.format(number));
+ } catch (NumberFormatException e) {
+ log.error(e.getMessage(), e);
+ return 0.0;
+ }
+ }
+
+ public static String toPercent(Number number) {
+ return toPercent(number, 0);
+ }
+
+ public static String toPercent(Number number, int offset) {
+ offset += 2;
+ Double num = fixedNum(number, offset);
+ return (num * 100) + "%";
+ }
+
+ /**
+ * convert bean to map
+ *
+ * @param bean bean
+ * @return map
+ */
+ public static <T> Map<String, Object> beanToMap(T bean) {
+ Map<String, Object> map = new HashMap<>();
+ if (bean != null) {
+ BeanMap beanMap = BeanMap.create(bean);
+ for (Object key : beanMap.keySet()) {
+ map.put(key + "", beanMap.get(key));
+ }
+ }
+ return map;
+ }
+
+ /**
+ * convert map to bean
+ *
+ * @param map map
+ * @param bean bean class
+ * @return bean
+ */
+ public static <T> T mapToBean(Map<String, Object> map, T bean) {
+ BeanMap beanMap = BeanMap.create(bean);
+ beanMap.putAll(map);
+ return bean;
+ }
+
+ /**
+ * convert List<T> to List<Map<String, Object>>
+ *
+ * @param objList
+ * @return
+ * @throws IOException
+ */
+ public static <T> List<Map<String, Object>> objectsToMaps(List<T> objList) {
+ List<Map<String, Object>> list = new ArrayList<>();
+ if (objList != null && objList.size() > 0) {
+ Map<String, Object> map = null;
+ T bean = null;
+ for (T t : objList) {
+ bean = t;
+ map = beanToMap(bean);
+ list.add(map);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * convert List<Map<String,Object>> to List<T>
+ *
+ * @param maps maps
+ * @param clazz element class
+ * @return
+ * @throws InstantiationException
+ * @throws IllegalAccessException
+ */
+ public static <T> List<T> mapsToObjects(List<Map<String, Object>> maps, Class<T> clazz)
+ throws InstantiationException, IllegalAccessException {
+ List<T> list = new ArrayList<>();
+ if (maps != null && maps.size() > 0) {
+ Map<String, Object> map;
+ T bean;
+ for (Map<String, Object> stringObjectMap : maps) {
+ map = stringObjectMap;
+ bean = clazz.newInstance();
+ mapToBean(map, bean);
+ list.add(bean);
+ }
+ }
+ return list;
+ }
+
+ public static Integer getPid() {
+ RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
+ String name = runtime.getName();
+ try {
+ return Integer.parseInt(name.substring(0, name.indexOf('@')));
+ } catch (Exception e) {
+ return -1;
+ }
+ }
+
+ public static boolean isLegalUrl(String url) {
+ try {
+ new URI(url);
+ return true;
+ } catch (Exception ignored) {
+ return false;
+ }
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/EncryptUtils.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/EncryptUtils.java
index d57884905..528d3dcbc 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/EncryptUtils.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/EncryptUtils.java
@@ -23,80 +23,80 @@ import java.security.Key;
public class EncryptUtils {
- private static final String DEFAULT_KEY = "defaultKey";
- private Cipher encryptCipher = null;
- private Cipher decryptCipher = null;
-
- private static String byteArr2HexStr(byte[] arrB) {
- int iLen = arrB.length;
- StringBuilder sb = new StringBuilder(iLen * 2);
- for (byte anArrB : arrB) {
- int intTmp = anArrB;
- while (intTmp < 0) {
- intTmp = intTmp + 256;
- }
- if (intTmp < 16) {
- sb.append("0");
- }
- sb.append(Integer.toString(intTmp, 16));
- }
- return sb.toString();
+ private static final String DEFAULT_KEY = "defaultKey";
+ private Cipher encryptCipher = null;
+ private Cipher decryptCipher = null;
+
+ private static String byteArr2HexStr(byte[] arrB) {
+ int iLen = arrB.length;
+ StringBuilder sb = new StringBuilder(iLen * 2);
+ for (byte anArrB : arrB) {
+ int intTmp = anArrB;
+ while (intTmp < 0) {
+ intTmp = intTmp + 256;
+ }
+ if (intTmp < 16) {
+ sb.append("0");
+ }
+ sb.append(Integer.toString(intTmp, 16));
}
+ return sb.toString();
+ }
- private static byte[] hexStr2ByteArr(String strIn) {
- byte[] arrB = strIn.getBytes();
- int iLen = arrB.length;
+ private static byte[] hexStr2ByteArr(String strIn) {
+ byte[] arrB = strIn.getBytes();
+ int iLen = arrB.length;
- byte[] arrOut = new byte[iLen / 2];
- for (int i = 0; i < iLen; i = i + 2) {
- String strTmp = new String(arrB, i, 2);
- arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16);
- }
- return arrOut;
+ byte[] arrOut = new byte[iLen / 2];
+ for (int i = 0; i < iLen; i = i + 2) {
+ String strTmp = new String(arrB, i, 2);
+ arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16);
}
-
- public EncryptUtils() throws Exception {
- this(DEFAULT_KEY);
- }
-
- EncryptUtils(String strKey) throws Exception {
- /*
- * Security.addProvider(new com.sun.crypto.provider.SunJCE());
- */
- Key key = getKey(strKey.getBytes());
-
- encryptCipher = Cipher.getInstance("DES");
- encryptCipher.init(Cipher.ENCRYPT_MODE, key);
-
- decryptCipher = Cipher.getInstance("DES");
- decryptCipher.init(Cipher.DECRYPT_MODE, key);
- }
-
- private byte[] encrypt(byte[] arrB) throws Exception {
- return encryptCipher.doFinal(arrB);
- }
-
- String encrypt(String strIn) throws Exception {
- return byteArr2HexStr(encrypt(strIn.getBytes()));
- }
-
- private byte[] decrypt(byte[] arrB) throws Exception {
- return decryptCipher.doFinal(arrB);
- }
-
- String decrypt(String strIn) {
- try {
- return new String(decrypt(hexStr2ByteArr(strIn)));
- } catch (Exception e) {
- return "";
- }
+ return arrOut;
+ }
+
+ public EncryptUtils() throws Exception {
+ this(DEFAULT_KEY);
+ }
+
+ EncryptUtils(String strKey) throws Exception {
+ /*
+ * Security.addProvider(new com.sun.crypto.provider.SunJCE());
+ */
+ Key key = getKey(strKey.getBytes());
+
+ encryptCipher = Cipher.getInstance("DES");
+ encryptCipher.init(Cipher.ENCRYPT_MODE, key);
+
+ decryptCipher = Cipher.getInstance("DES");
+ decryptCipher.init(Cipher.DECRYPT_MODE, key);
+ }
+
+ private byte[] encrypt(byte[] arrB) throws Exception {
+ return encryptCipher.doFinal(arrB);
+ }
+
+ String encrypt(String strIn) throws Exception {
+ return byteArr2HexStr(encrypt(strIn.getBytes()));
+ }
+
+ private byte[] decrypt(byte[] arrB) throws Exception {
+ return decryptCipher.doFinal(arrB);
+ }
+
+ String decrypt(String strIn) {
+ try {
+ return new String(decrypt(hexStr2ByteArr(strIn)));
+ } catch (Exception e) {
+ return "";
}
+ }
- private Key getKey(byte[] arrBTmp) {
- byte[] arrB = new byte[8];
- for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
- arrB[i] = arrBTmp[i];
- }
- return new javax.crypto.spec.SecretKeySpec(arrB, "DES");
+ private Key getKey(byte[] arrBTmp) {
+ byte[] arrB = new byte[8];
+ for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
+ arrB[i] = arrBTmp[i];
}
+ return new javax.crypto.spec.SecretKeySpec(arrB, "DES");
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/FileUtils.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/FileUtils.java
index d7402c5f0..544e603ea 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/FileUtils.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/FileUtils.java
@@ -21,55 +21,54 @@ import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
-/**
- * The file utils.
- */
+/** The file utils. */
public class FileUtils {
- /**
- * Read the end of the file.
- *
- * @param file The file
- * @param maxSize Maximum size of read file
- * @return The file content
- * @throws IOException
- */
- public static byte[] readEndOfFile(File file, long maxSize) throws IOException {
- long readSize = maxSize;
- byte[] fileContent;
- try (RandomAccessFile raFile = new RandomAccessFile(file, "r")) {
- if (raFile.length() > maxSize) {
- raFile.seek(raFile.length() - maxSize);
- } else if (raFile.length() < maxSize) {
- readSize = (int) raFile.length();
- }
- fileContent = new byte[(int) readSize];
- raFile.read(fileContent);
- }
- return fileContent;
+ /**
+ * Read the end of the file.
+ *
+ * @param file The file
+ * @param maxSize Maximum size of read file
+ * @return The file content
+ * @throws IOException
+ */
+ public static byte[] readEndOfFile(File file, long maxSize) throws IOException {
+ long readSize = maxSize;
+ byte[] fileContent;
+ try (RandomAccessFile raFile = new RandomAccessFile(file, "r")) {
+ if (raFile.length() > maxSize) {
+ raFile.seek(raFile.length() - maxSize);
+ } else if (raFile.length() < maxSize) {
+ readSize = (int) raFile.length();
+ }
+ fileContent = new byte[(int) readSize];
+ raFile.read(fileContent);
}
+ return fileContent;
+ }
- /**
- * Read the end of the file.
- *
- * @param file The file
- * @param maxSize Maximum size of read file
- * @return The file content
- * @throws IOException
- */
- public static byte[] readFileFromOffset(File file, long startOffset, long maxSize) throws IOException {
- if (file.length() < startOffset) {
- throw new IllegalArgumentException(
- String.format("The startOffset %s is great than the file length %s", startOffset, file.length()));
- }
- byte[] fileContent;
- try (RandomAccessFile raFile = new RandomAccessFile(file, "r")) {
- long readSize = Math.min(maxSize, file.length() - startOffset);
- raFile.seek(startOffset);
- fileContent = new byte[(int) readSize];
- raFile.read(fileContent);
- }
- return fileContent;
+ /**
+ * Read the end of the file.
+ *
+ * @param file The file
+ * @param maxSize Maximum size of read file
+ * @return The file content
+ * @throws IOException
+ */
+ public static byte[] readFileFromOffset(File file, long startOffset, long maxSize)
+ throws IOException {
+ if (file.length() < startOffset) {
+ throw new IllegalArgumentException(
+ String.format(
+ "The startOffset %s is great than the file length %s", startOffset, file.length()));
}
-
+ byte[] fileContent;
+ try (RandomAccessFile raFile = new RandomAccessFile(file, "r")) {
+ long readSize = Math.min(maxSize, file.length() - startOffset);
+ raFile.seek(startOffset);
+ fileContent = new byte[(int) readSize];
+ raFile.read(fileContent);
+ }
+ return fileContent;
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/FreemarkerUtils.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/FreemarkerUtils.java
index bc5cea2c6..518a056b4 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/FreemarkerUtils.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/FreemarkerUtils.java
@@ -29,41 +29,42 @@ import java.io.IOException;
import java.io.StringWriter;
@Slf4j
-public class FreemarkerUtils {
- private static final Configuration CONFIGURATION;
+public class FreemarkerUtils {
+ private static final Configuration CONFIGURATION;
- static {
- SpringTemplateLoader templateLoader = new SpringTemplateLoader(new DefaultResourceLoader(), "classpath:alert-template");
- CONFIGURATION = new Configuration(Configuration.VERSION_2_3_28);
- CONFIGURATION.setTemplateLoader(templateLoader);
- CONFIGURATION.setDefaultEncoding("UTF-8");
- }
+ static {
+ SpringTemplateLoader templateLoader =
+ new SpringTemplateLoader(new DefaultResourceLoader(), "classpath:alert-template");
+ CONFIGURATION = new Configuration(Configuration.VERSION_2_3_28);
+ CONFIGURATION.setTemplateLoader(templateLoader);
+ CONFIGURATION.setDefaultEncoding("UTF-8");
+ }
- public static Template loadTemplateFile(String fileName) throws ExceptionInInitializerError {
- try {
- return CONFIGURATION.getTemplate(fileName);
- } catch (IOException e) {
- log.error("{} not found!", fileName);
- throw new ExceptionInInitializerError(fileName + " not found!");
- }
+ public static Template loadTemplateFile(String fileName) throws ExceptionInInitializerError {
+ try {
+ return CONFIGURATION.getTemplate(fileName);
+ } catch (IOException e) {
+ log.error("{} not found!", fileName);
+ throw new ExceptionInInitializerError(fileName + " not found!");
}
+ }
- public static Template loadTemplateString(String template) throws Exception {
- Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);
- StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();
- stringTemplateLoader.putTemplate("template", template);
- configuration.setTemplateLoader(stringTemplateLoader);
- return configuration.getTemplate("template");
- }
+ public static Template loadTemplateString(String template) throws Exception {
+ Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);
+ StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();
+ stringTemplateLoader.putTemplate("template", template);
+ configuration.setTemplateLoader(stringTemplateLoader);
+ return configuration.getTemplate("template");
+ }
- public static String format(Template template, Object dataModel) throws TemplateException {
- String result = null;
- try (StringWriter writer = new StringWriter()) {
- template.process(dataModel, writer);
- result = writer.toString();
- } catch (IOException e) {
- log.error(e.getMessage());
- }
- return result;
+ public static String format(Template template, Object dataModel) throws TemplateException {
+ String result = null;
+ try (StringWriter writer = new StringWriter()) {
+ template.process(dataModel, writer);
+ result = writer.toString();
+ } catch (IOException e) {
+ log.error(e.getMessage());
}
+ return result;
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/GZipUtils.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/GZipUtils.java
index 4ef03430c..ca64bbd38 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/GZipUtils.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/GZipUtils.java
@@ -32,80 +32,78 @@ import java.util.zip.GZIPInputStream;
@Slf4j
public final class GZipUtils {
- private GZipUtils() {
+ private GZipUtils() {}
- }
-
- /**
- * @param tarZipSource source dir
- * @param targetDir target dir
- */
- public static File decompress(String tarZipSource, String targetDir) {
- File unFile = null;
- // tar compress format
- ArchiveStreamFactory archiveStreamFactory = new ArchiveStreamFactory();
- try (
- FileInputStream inputStream = new FileInputStream(tarZipSource);
- BufferedInputStream bufInput = new BufferedInputStream(inputStream);
- GZIPInputStream gzipInput = new GZIPInputStream(bufInput);
- ArchiveInputStream archiveInput = archiveStreamFactory.createArchiveInputStream("tar", gzipInput)) {
+ /**
+ * @param tarZipSource source dir
+ * @param targetDir target dir
+ */
+ public static File decompress(String tarZipSource, String targetDir) {
+ File unFile = null;
+ // tar compress format
+ ArchiveStreamFactory archiveStreamFactory = new ArchiveStreamFactory();
+ try (FileInputStream inputStream = new FileInputStream(tarZipSource);
+ BufferedInputStream bufInput = new BufferedInputStream(inputStream);
+ GZIPInputStream gzipInput = new GZIPInputStream(bufInput);
+ ArchiveInputStream archiveInput =
+ archiveStreamFactory.createArchiveInputStream("tar", gzipInput)) {
- TarArchiveEntry entry = (TarArchiveEntry) archiveInput.getNextEntry();
+ TarArchiveEntry entry = (TarArchiveEntry) archiveInput.getNextEntry();
- while (entry != null) {
- String entryName = entry.getName();
+ while (entry != null) {
+ String entryName = entry.getName();
- if (entry.isDirectory()) {
- createDir(targetDir, entryName, 1);
- if (unFile == null) {
- unFile = new File(targetDir + entryName.replaceAll("/.*$", ""));
- }
- } else if (entry.isFile()) {
- String fullFileName = createDir(targetDir, entryName, 2);
- try (FileOutputStream outputStream = new FileOutputStream(fullFileName);
- BufferedOutputStream bufOutput = new BufferedOutputStream(outputStream)) {
- int b = -1;
- while ((b = archiveInput.read()) != -1) {
- bufOutput.write(b);
- }
- }
- }
- entry = (TarArchiveEntry) archiveInput.getNextEntry();
+ if (entry.isDirectory()) {
+ createDir(targetDir, entryName, 1);
+ if (unFile == null) {
+ unFile = new File(targetDir + entryName.replaceAll("/.*$", ""));
+ }
+ } else if (entry.isFile()) {
+ String fullFileName = createDir(targetDir, entryName, 2);
+ try (FileOutputStream outputStream = new FileOutputStream(fullFileName);
+ BufferedOutputStream bufOutput = new BufferedOutputStream(outputStream)) {
+ int b = -1;
+ while ((b = archiveInput.read()) != -1) {
+ bufOutput.write(b);
}
- } catch (Exception e) {
- log.error(e.getMessage(), e);
+ }
}
-
- return unFile;
+ entry = (TarArchiveEntry) archiveInput.getNextEntry();
+ }
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
}
- /**
- * @param baseDir baseDir
- * @param entry archive entry
- * @param type type: 1, dir; 2, file
- * @return
- */
- private static String createDir(String baseDir, String entry, int type) {
- String[] items = entry.split("/");
- String fullFilePath = baseDir;
- for (int i = 0; i < items.length; i++) {
- String item = items[i];
- fullFilePath = fullFilePath + File.separator + item;
- if (type == 2) {
- if (i != items.length - 1) {
- File tmpFile = new File(fullFilePath);
- if (!tmpFile.exists()) {
- tmpFile.mkdir();
- }
- }
- } else {
- File tmpFile = new File(fullFilePath);
- if (!tmpFile.exists()) {
- tmpFile.mkdir();
- }
- }
+ return unFile;
+ }
+
+ /**
+ * @param baseDir baseDir
+ * @param entry archive entry
+ * @param type type: 1, dir; 2, file
+ * @return
+ */
+ private static String createDir(String baseDir, String entry, int type) {
+ String[] items = entry.split("/");
+ String fullFilePath = baseDir;
+ for (int i = 0; i < items.length; i++) {
+ String item = items[i];
+ fullFilePath = fullFilePath + File.separator + item;
+ if (type == 2) {
+ if (i != items.length - 1) {
+ File tmpFile = new File(fullFilePath);
+ if (!tmpFile.exists()) {
+ tmpFile.mkdir();
+ }
+ }
+ } else {
+ File tmpFile = new File(fullFilePath);
+ if (!tmpFile.exists()) {
+ tmpFile.mkdir();
}
- File fullFile = new File(fullFilePath);
- return fullFile.getAbsolutePath();
+ }
}
+ File fullFile = new File(fullFilePath);
+ return fullFile.getAbsolutePath();
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/GitUtils.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/GitUtils.java
index 4bd548dd2..995575ba1 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/GitUtils.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/GitUtils.java
@@ -42,78 +42,77 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
-/**
- *
- */
+/** */
public class GitUtils {
- public static Git clone(Project project) throws GitAPIException {
- CloneCommand cloneCommand = Git.cloneRepository()
- .setURI(project.getUrl())
- .setDirectory(project.getAppSource());
+ public static Git clone(Project project) throws GitAPIException {
+ CloneCommand cloneCommand =
+ Git.cloneRepository().setURI(project.getUrl()).setDirectory(project.getAppSource());
- if (project.getBranches() != null) {
- cloneCommand.setBranch(Constants.R_HEADS + project.getBranches());
- cloneCommand.setBranchesToClone(Collections.singletonList(Constants.R_HEADS + project.getBranches()));
- }
- setCredentials(cloneCommand, project);
- return cloneCommand.call();
+ if (project.getBranches() != null) {
+ cloneCommand.setBranch(Constants.R_HEADS + project.getBranches());
+ cloneCommand.setBranchesToClone(
+ Collections.singletonList(Constants.R_HEADS + project.getBranches()));
}
+ setCredentials(cloneCommand, project);
+ return cloneCommand.call();
+ }
- public static List<String> getBranchList(Project project) throws GitAPIException {
- LsRemoteCommand command = Git.lsRemoteRepository()
- .setRemote(project.getUrl())
- .setHeads(true);
- setCredentials(command, project);
- Collection<Ref> refList = command.call();
- List<String> branchList = new ArrayList<>(4);
- for (Ref ref : refList) {
- String refName = ref.getName();
- if (refName.startsWith(Constants.R_HEADS)) {
- String branchName = refName.replace(Constants.R_HEADS, "");
- branchList.add(branchName);
- }
- }
- return branchList;
+ public static List<String> getBranchList(Project project) throws GitAPIException {
+ LsRemoteCommand command = Git.lsRemoteRepository().setRemote(project.getUrl()).setHeads(true);
+ setCredentials(command, project);
+ Collection<Ref> refList = command.call();
+ List<String> branchList = new ArrayList<>(4);
+ for (Ref ref : refList) {
+ String refName = ref.getName();
+ if (refName.startsWith(Constants.R_HEADS)) {
+ String branchName = refName.replace(Constants.R_HEADS, "");
+ branchList.add(branchName);
+ }
}
+ return branchList;
+ }
- private static void setCredentials(TransportCommand<?, ?> transportCommand, Project project) {
- GitProtocol gitProtocol = GitProtocol.of(project.getGitProtocol());
- switch (gitProtocol) {
- case HTTPS:
- if (!StringUtils.isAllEmpty(project.getUserName(), project.getPassword())) {
- UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(project.getUserName(), project.getPassword());
- transportCommand.setCredentialsProvider(credentialsProvider);
- }
- break;
- case SSH:
- transportCommand.setTransportConfigCallback(transport -> {
- SshTransport sshTransport = (SshTransport) transport;
- sshTransport.setSshSessionFactory(new JschConfigSessionFactory() {
- @Override
- protected void configure(OpenSshConfig.Host hc, Session session) {
- session.setConfig("StrictHostKeyChecking", "no");
- }
-
- @Override
- protected JSch createDefaultJSch(FS fs) throws JSchException {
- JSch jSch = super.createDefaultJSch(fs);
- if (project.getRsaPath() == null) {
- return jSch;
- }
- if (StringUtils.isEmpty(project.getPassword())) {
- jSch.addIdentity(project.getRsaPath());
- } else {
- jSch.addIdentity(project.getRsaPath(), project.getPassword());
- }
- return jSch;
- }
- });
- });
- break;
- default:
- throw new IllegalStateException("[StreamPark] git setCredentials: unsupported protocol type");
+ private static void setCredentials(TransportCommand<?, ?> transportCommand, Project project) {
+ GitProtocol gitProtocol = GitProtocol.of(project.getGitProtocol());
+ switch (gitProtocol) {
+ case HTTPS:
+ if (!StringUtils.isAllEmpty(project.getUserName(), project.getPassword())) {
+ UsernamePasswordCredentialsProvider credentialsProvider =
+ new UsernamePasswordCredentialsProvider(project.getUserName(), project.getPassword());
+ transportCommand.setCredentialsProvider(credentialsProvider);
}
- }
+ break;
+ case SSH:
+ transportCommand.setTransportConfigCallback(
+ transport -> {
+ SshTransport sshTransport = (SshTransport) transport;
+ sshTransport.setSshSessionFactory(
+ new JschConfigSessionFactory() {
+ @Override
+ protected void configure(OpenSshConfig.Host hc, Session session) {
+ session.setConfig("StrictHostKeyChecking", "no");
+ }
+ @Override
+ protected JSch createDefaultJSch(FS fs) throws JSchException {
+ JSch jSch = super.createDefaultJSch(fs);
+ if (project.getRsaPath() == null) {
+ return jSch;
+ }
+ if (StringUtils.isEmpty(project.getPassword())) {
+ jSch.addIdentity(project.getRsaPath());
+ } else {
+ jSch.addIdentity(project.getRsaPath(), project.getPassword());
+ }
+ return jSch;
+ }
+ });
+ });
+ break;
+ default:
+ throw new IllegalStateException(
+ "[StreamPark] git setCredentials: unsupported protocol type");
+ }
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/JacksonUtils.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/JacksonUtils.java
index f179fdfac..2d99c7bbf 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/JacksonUtils.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/JacksonUtils.java
@@ -31,32 +31,30 @@ import java.text.SimpleDateFormat;
public final class JacksonUtils {
- private JacksonUtils() {
-
- }
-
- private static final ObjectMapper MAPPER;
-
- static {
- MAPPER = new ObjectMapper();
- MAPPER.registerModule(new DefaultScalaModule());
- MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- MAPPER.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
- MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
- MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
- MAPPER.setDateFormat(new SimpleDateFormat(DateUtils.fullFormat()));
- }
-
- public static <T> T read(String json, Class<T> clazz) throws JsonProcessingException {
- return MAPPER.readValue(json, clazz);
- }
-
- public static <T> T read(String json, TypeReference<T> typeReference) throws JsonProcessingException {
- return MAPPER.readValue(json, typeReference);
- }
-
- public static String write(Object object) throws JsonProcessingException {
- return MAPPER.writeValueAsString(object);
- }
-
+ private JacksonUtils() {}
+
+ private static final ObjectMapper MAPPER;
+
+ static {
+ MAPPER = new ObjectMapper();
+ MAPPER.registerModule(new DefaultScalaModule());
+ MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ MAPPER.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
+ MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
+ MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ MAPPER.setDateFormat(new SimpleDateFormat(DateUtils.fullFormat()));
+ }
+
+ public static <T> T read(String json, Class<T> clazz) throws JsonProcessingException {
+ return MAPPER.readValue(json, clazz);
+ }
+
+ public static <T> T read(String json, TypeReference<T> typeReference)
+ throws JsonProcessingException {
+ return MAPPER.readValue(json, typeReference);
+ }
+
+ public static String write(Object object) throws JsonProcessingException {
+ return MAPPER.writeValueAsString(object);
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/MoreFutures.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/MoreFutures.java
index 83d2b6575..78fbecf7b 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/MoreFutures.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/MoreFutures.java
@@ -28,94 +28,98 @@ import java.util.function.Function;
import java.util.function.Supplier;
public final class MoreFutures {
- private MoreFutures() {
- }
+ private MoreFutures() {}
- public static <T> T await(CompletionStage<T> stage) {
- CompletableFuture<T> future = stage.toCompletableFuture();
+ public static <T> T await(CompletionStage<T> stage) {
+ CompletableFuture<T> future = stage.toCompletableFuture();
- try {
- return future.get();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- } catch (ExecutionException e) {
- throw new RuntimeException(e.getCause());
- }
+ try {
+ return future.get();
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ } catch (ExecutionException e) {
+ throw new RuntimeException(e.getCause());
}
+ }
- public static <T> T deref(CompletionStage<T> stage, long timeout, TimeUnit unit) {
- CompletableFuture<T> future = stage.toCompletableFuture();
+ public static <T> T deref(CompletionStage<T> stage, long timeout, TimeUnit unit) {
+ CompletableFuture<T> future = stage.toCompletableFuture();
- try {
- return future.get(timeout, unit);
- } catch (TimeoutException | InterruptedException e) {
- throw new RuntimeException(e);
- } catch (ExecutionException e) {
- throw new RuntimeException(e.getCause());
- }
+ try {
+ return future.get(timeout, unit);
+ } catch (TimeoutException | InterruptedException e) {
+ throw new RuntimeException(e);
+ } catch (ExecutionException e) {
+ throw new RuntimeException(e.getCause());
}
-
- public static <T> T derefUsingDefaultTimeout(CompletionStage<T> stage) {
- return deref(stage, 5L, TimeUnit.SECONDS);
+ }
+
+ public static <T> T derefUsingDefaultTimeout(CompletionStage<T> stage) {
+ return deref(stage, 5L, TimeUnit.SECONDS);
+ }
+
+ public static <T> CompletionStage<T> exceptionallyCompose(
+ CompletionStage<T> stage, Function<Throwable, ? extends CompletionStage<T>> fn) {
+ return stage
+ .thenApply(CompletableFuture::completedFuture)
+ .exceptionally((Function<Throwable, ? extends CompletableFuture<T>>) fn)
+ .thenCompose(Function.identity());
+ }
+
+ public static <T> CompletableFuture<T> completeImmediately(Supplier<T> supplier) {
+ try {
+ return CompletableFuture.completedFuture(supplier.get());
+ } catch (Throwable e) {
+ CompletableFuture<T> f = new CompletableFuture<>();
+ f.completeExceptionally(e);
+ return f;
}
+ }
- public static <T> CompletionStage<T> exceptionallyCompose(CompletionStage<T> stage, Function<Throwable, ? extends CompletionStage<T>> fn) {
- return stage.thenApply(CompletableFuture::completedFuture).exceptionally((Function<Throwable, ? extends CompletableFuture<T>>) fn).thenCompose(Function.identity());
- }
+ public static <T> CompletableFuture<T> completedExceptionally(Throwable cause) {
+ CompletableFuture<T> future = new CompletableFuture<>();
+ future.completeExceptionally(cause);
+ return future;
+ }
- public static <T> CompletableFuture<T> completeImmediately(Supplier<T> supplier) {
- try {
- return CompletableFuture.completedFuture(supplier.get());
- } catch (Throwable e) {
- CompletableFuture<T> f = new CompletableFuture<>();
- f.completeExceptionally(e);
- return f;
- }
- }
+ public static <T> ScheduledFuture<T> completedScheduledFuture(T value) {
+ return new CompletedScheduledFuture<>(value);
+ }
- public static <T> CompletableFuture<T> completedExceptionally(Throwable cause) {
- CompletableFuture<T> future = new CompletableFuture<>();
- future.completeExceptionally(cause);
- return future;
- }
+ private static final class CompletedScheduledFuture<T> implements ScheduledFuture<T> {
+ private final T value;
- public static <T> ScheduledFuture<T> completedScheduledFuture(T value) {
- return new CompletedScheduledFuture<>(value);
+ private CompletedScheduledFuture(T value) {
+ this.value = value;
}
- private static final class CompletedScheduledFuture<T> implements ScheduledFuture<T> {
- private final T value;
-
- private CompletedScheduledFuture(T value) {
- this.value = value;
- }
-
- public long getDelay(TimeUnit unit) {
- return 0L;
- }
+ public long getDelay(TimeUnit unit) {
+ return 0L;
+ }
- public int compareTo(Delayed o) {
- return Long.compare(0L, o.getDelay(TimeUnit.MILLISECONDS));
- }
+ public int compareTo(Delayed o) {
+ return Long.compare(0L, o.getDelay(TimeUnit.MILLISECONDS));
+ }
- public boolean cancel(boolean mayInterruptIfRunning) {
- return false;
- }
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ return false;
+ }
- public boolean isCancelled() {
- return false;
- }
+ public boolean isCancelled() {
+ return false;
+ }
- public boolean isDone() {
- return true;
- }
+ public boolean isDone() {
+ return true;
+ }
- public T get() throws InterruptedException, ExecutionException {
- return this.value;
- }
+ public T get() throws InterruptedException, ExecutionException {
+ return this.value;
+ }
- public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
- return this.value;
- }
+ public T get(long timeout, TimeUnit unit)
+ throws InterruptedException, ExecutionException, TimeoutException {
+ return this.value;
}
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/ObjectUtils.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/ObjectUtils.java
index c36ee4d20..f375dad52 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/ObjectUtils.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/ObjectUtils.java
@@ -22,895 +22,895 @@ import java.util.Arrays;
public final class ObjectUtils {
- private ObjectUtils() {
-
- }
-
- private static final int INITIAL_HASH = 7;
- private static final int MULTIPLIER = 31;
-
- private static final String EMPTY_STRING = "";
- private static final String NULL_STRING = "null";
- private static final String ARRAY_START = "{";
- private static final String ARRAY_END = "}";
- private static final String EMPTY_ARRAY = ARRAY_START + ARRAY_END;
- private static final String ARRAY_ELEMENT_SEPARATOR = ", ";
-
- /**
- * Return whether the given throwable is a checked exception: that is, neither a RuntimeException
- * nor an Error.
- *
- * @param ex the throwable to check
- * @return whether the throwable is a checked exception
- * @see Exception
- * @see RuntimeException
- * @see Error
- */
- public static boolean isCheckedException(Throwable ex) {
- return !(ex instanceof RuntimeException || ex instanceof Error);
- }
-
- /**
- * Check whether the given exception is compatible with the exceptions declared in a throws
- * clause.
- *
- * @param ex the exception to checked
- * @param declaredExceptions the exceptions declared in the throws clause
- * @return whether the given exception is compatible
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- public static boolean isCompatibleWithThrowsClause(Throwable ex, Class[] declaredExceptions) {
- if (!isCheckedException(ex)) {
- return true;
- }
- if (declaredExceptions != null) {
- int i = 0;
- while (i < declaredExceptions.length) {
- if (declaredExceptions[i].isAssignableFrom(ex.getClass())) {
- return true;
- }
- i++;
- }
- }
- return false;
- }
-
- /**
- * Determine whether the given object is an array: either an Object array or a primitive array.
- *
- * @param obj the object to check
- */
- public static boolean isArray(Object obj) {
- return (obj != null && obj.getClass().isArray());
- }
-
- /**
- * Determine whether the given array is empty: i.e. <code>null</code> or of zero length.
- *
- * @param array the array to check
- */
- public static boolean isEmpty(Object[] array) {
- return (array == null || array.length == 0);
- }
-
- /**
- * Check whether the given array contains the given element.
- *
- * @param array the array to check (may be <code>null</code>, in which case the return value will
- * always be <code>false</code>)
- * @param element the element to check for
- * @return whether the element has been found in the given array
- */
- public static boolean containsElement(Object[] array, Object element) {
- if (array == null) {
- return false;
- }
- for (Object arrayEle : array) {
- if (safeEquals(arrayEle, element)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Check whether the given array of enum constants contains a constant with the given name,
- * ignoring case when determining a match.
- *
- * @param enumValues the enum values to check, typically the product of a call to MyEnum.values()
- * @param constant the constant name to find (must not be null or empty string)
- * @return whether the constant has been found in the given array
- */
- public static boolean containsConstant(Enum<?>[] enumValues, String constant) {
- return containsConstant(enumValues, constant, false);
- }
-
- /**
- * Check whether the given array of enum constants contains a constant with the given name.
- *
- * @param enumValues the enum values to check, typically the product of a call to MyEnum.values()
- * @param constant the constant name to find (must not be null or empty string)
- * @param caseSensitive whether case is significant in determining a match
- * @return whether the constant has been found in the given array
- */
- public static boolean containsConstant(
- Enum<?>[] enumValues, String constant, boolean caseSensitive) {
- for (Enum<?> candidate : enumValues) {
- if (caseSensitive ? candidate.toString().equals(constant) : candidate.toString().equalsIgnoreCase(constant)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Case insensitive alternative to {@link Enum#valueOf(Class, String)}.
- *
- * @param <E> the concrete Enum type
- * @param enumValues the array of all Enum constants in question, usually per Enum.values()
- * @param constant the constant to get the enum value of
- * @throws IllegalArgumentException if the given constant is not found in the given array of enum
- * values. Use {@link #containsConstant(Enum[], String)} as a guard to avoid this exception.
- */
- public static <E extends Enum<?>> E caseInsensitiveValueOf(E[] enumValues, String constant) {
- for (E candidate : enumValues) {
- if (candidate.toString().equalsIgnoreCase(constant)) {
- return candidate;
- }
- }
- throw new IllegalArgumentException(
- String.format(
- "constant [%s] does not exist in enum type %s",
- constant, enumValues.getClass().getComponentType().getName()));
- }
-
- /**
- * Append the given object to the given array, returning a new array consisting of the input array
- * contents plus the given object.
- *
- * @param array the array to append to (can be <code>null</code>)
- * @param obj the object to append
- * @return the new array (of the same component type; never <code>null</code>)
- */
- public static <A, O extends A> A[] addObjectToArray(A[] array, O obj) {
- Class<?> compType = Object.class;
- if (array != null) {
- compType = array.getClass().getComponentType();
- } else if (obj != null) {
- compType = obj.getClass();
- }
- int newArrLength = (array != null ? array.length + 1 : 1);
- @SuppressWarnings("unchecked")
- A[] newArr = (A[]) Array.newInstance(compType, newArrLength);
- if (array != null) {
- System.arraycopy(array, 0, newArr, 0, array.length);
- }
- newArr[newArr.length - 1] = obj;
- return newArr;
- }
-
- /**
- * Convert the given array (which may be a primitive array) to an object array (if necessary of
- * primitive wrapper objects).
- *
- * <p>A <code>null</code> source value will be converted to an empty Object array.
- *
- * @param source the (potentially primitive) array
- * @return the corresponding object array (never <code>null</code>)
- * @throws IllegalArgumentException if the parameter is not an array
- */
- public static Object[] toObjectArray(Object source) {
- if (source instanceof Object[]) {
- return (Object[]) source;
- }
- if (source == null) {
- return new Object[0];
- }
- if (!source.getClass().isArray()) {
- throw new IllegalArgumentException("Source is not an array: " + source);
- }
- int length = Array.getLength(source);
- if (length == 0) {
- return new Object[0];
- }
- @SuppressWarnings("rawtypes")
- Class wrapperType = Array.get(source, 0).getClass();
- Object[] newArray = (Object[]) Array.newInstance(wrapperType, length);
- for (int i = 0; i < length; i++) {
- newArray[i] = Array.get(source, i);
- }
- return newArray;
- }
-
- // ---------------------------------------------------------------------
- // Convenience methods for content-based equality/hash-code handling
- // ---------------------------------------------------------------------
-
- /**
- * Determine if the given objects are equal, returning <code>true</code> if both are <code>null
- * </code> or <code>false</code> if only one is <code>null</code>.
- *
- * <p>Compares arrays with <code>Arrays.equals</code>, performing an equality check based on the
- * array elements rather than the array reference.
- *
- * @param o1 first Object to compare
- * @param o2 second Object to compare
- * @return whether the given objects are equal
- * @see Arrays#equals
- */
- public static boolean safeEquals(Object o1, Object o2) {
- if (o1 == null || o2 == null) {
- return false;
- }
-
- if (o1 == o2) {
- return true;
- }
-
- if (o1.equals(o2)) {
- return true;
- }
- if (o1.getClass().isArray() && o2.getClass().isArray()) {
- if (o1 instanceof Object[] && o2 instanceof Object[]) {
- return Arrays.equals((Object[]) o1, (Object[]) o2);
- }
- if (o1 instanceof boolean[] && o2 instanceof boolean[]) {
- return Arrays.equals((boolean[]) o1, (boolean[]) o2);
- }
- if (o1 instanceof byte[] && o2 instanceof byte[]) {
- return Arrays.equals((byte[]) o1, (byte[]) o2);
- }
- if (o1 instanceof char[] && o2 instanceof char[]) {
- return Arrays.equals((char[]) o1, (char[]) o2);
- }
- if (o1 instanceof double[] && o2 instanceof double[]) {
- return Arrays.equals((double[]) o1, (double[]) o2);
- }
- if (o1 instanceof float[] && o2 instanceof float[]) {
- return Arrays.equals((float[]) o1, (float[]) o2);
- }
- if (o1 instanceof int[] && o2 instanceof int[]) {
- return Arrays.equals((int[]) o1, (int[]) o2);
- }
- if (o1 instanceof long[] && o2 instanceof long[]) {
- return Arrays.equals((long[]) o1, (long[]) o2);
- }
- if (o1 instanceof short[] && o2 instanceof short[]) {
- return Arrays.equals((short[]) o1, (short[]) o2);
- }
- }
- return false;
- }
-
- public static boolean safeTrimEquals(Object o1, Object o2) {
- boolean equals = safeEquals(o1, o2);
- if (!equals) {
- if (o1 != null && o2 != null) {
- if (o1 instanceof String && o2 instanceof String) {
- return o1.toString().trim().equals(o2.toString().trim());
- }
- }
- }
- return equals;
- }
-
- /**
- * Return as hash code for the given object; typically the value of <code>
- * {@link Object#hashCode()}</code>. If the object is an array, this method will delegate to any
- * of the <code>safeHashCode</code> methods for arrays in this class. If the object is <code>null
- * </code>, this method returns 0.
- *
- * @see #safeHashCode(Object[])
- * @see #safeHashCode(boolean[])
- * @see #safeHashCode(byte[])
- * @see #safeHashCode(char[])
- * @see #safeHashCode(double[])
- * @see #safeHashCode(float[])
- * @see #safeHashCode(int[])
- * @see #safeHashCode(long[])
- * @see #safeHashCode(short[])
- */
- public static int safeHashCode(Object obj) {
- if (obj == null) {
- return 0;
- }
- if (obj.getClass().isArray()) {
- if (obj instanceof Object[]) {
- return safeHashCode((Object[]) obj);
- }
- if (obj instanceof boolean[]) {
- return safeHashCode((boolean[]) obj);
- }
- if (obj instanceof byte[]) {
- return safeHashCode((byte[]) obj);
- }
- if (obj instanceof char[]) {
- return safeHashCode((char[]) obj);
- }
- if (obj instanceof double[]) {
- return safeHashCode((double[]) obj);
- }
- if (obj instanceof float[]) {
- return safeHashCode((float[]) obj);
- }
- if (obj instanceof int[]) {
- return safeHashCode((int[]) obj);
- }
- if (obj instanceof long[]) {
- return safeHashCode((long[]) obj);
- }
- if (obj instanceof short[]) {
- return safeHashCode((short[]) obj);
- }
- }
- return obj.hashCode();
- }
-
- /**
- * Return a hash code based on the contents of the specified array. If <code>array</code> is
- * <code>null</code>, this method returns 0.
- */
- public static int safeHashCode(Object[] array) {
- if (array == null) {
- return 0;
- }
- int hash = INITIAL_HASH;
- for (Object anArray : array) {
- hash = MULTIPLIER * hash + safeHashCode(anArray);
- }
- return hash;
- }
-
- /**
- * Return a hash code based on the contents of the specified array. If <code>array</code> is
- * <code>null</code>, this method returns 0.
- */
- public static int safeHashCode(boolean[] array) {
- if (array == null) {
- return 0;
- }
- int hash = INITIAL_HASH;
- for (boolean anArray : array) {
- hash = MULTIPLIER * hash + hashCode(anArray);
- }
- return hash;
- }
-
- /**
- * Return a hash code based on the contents of the specified array. If <code>array</code> is
- * <code>null</code>, this method returns 0.
- */
- public static int safeHashCode(byte[] array) {
- if (array == null) {
- return 0;
- }
- int hash = INITIAL_HASH;
- for (byte anArray : array) {
- hash = MULTIPLIER * hash + anArray;
- }
- return hash;
- }
-
- /**
- * Return a hash code based on the contents of the specified array. If <code>array</code> is
- * <code>null</code>, this method returns 0.
- */
- public static int safeHashCode(char[] array) {
- if (array == null) {
- return 0;
- }
- int hash = INITIAL_HASH;
- for (char anArray : array) {
- hash = MULTIPLIER * hash + anArray;
- }
- return hash;
- }
-
- /**
- * Return a hash code based on the contents of the specified array. If <code>array</code> is
- * <code>null</code>, this method returns 0.
- */
- public static int safeHashCode(double[] array) {
- if (array == null) {
- return 0;
- }
- int hash = INITIAL_HASH;
- for (double anArray : array) {
- hash = MULTIPLIER * hash + hashCode(anArray);
- }
- return hash;
- }
-
- /**
- * Return a hash code based on the contents of the specified array. If <code>array</code> is
- * <code>null</code>, this method returns 0.
- */
- public static int safeHashCode(float[] array) {
- if (array == null) {
- return 0;
- }
- int hash = INITIAL_HASH;
- for (float anArray : array) {
- hash = MULTIPLIER * hash + hashCode(anArray);
- }
- return hash;
- }
-
- /**
- * Return a hash code based on the contents of the specified array. If <code>array</code> is
- * <code>null</code>, this method returns 0.
- */
- public static int safeHashCode(int[] array) {
- if (array == null) {
- return 0;
- }
- int hash = INITIAL_HASH;
- for (int anArray : array) {
- hash = MULTIPLIER * hash + anArray;
- }
- return hash;
- }
-
- /**
- * Return a hash code based on the contents of the specified array. If <code>array</code> is
- * <code>null</code>, this method returns 0.
- */
- public static int safeHashCode(long[] array) {
- if (array == null) {
- return 0;
- }
- int hash = INITIAL_HASH;
- for (long anArray : array) {
- hash = MULTIPLIER * hash + hashCode(anArray);
- }
- return hash;
- }
-
- /**
- * Return a hash code based on the contents of the specified array. If <code>array</code> is
- * <code>null</code>, this method returns 0.
- */
- public static int safeHashCode(short[] array) {
- if (array == null) {
- return 0;
- }
- int hash = INITIAL_HASH;
- for (short anArray : array) {
- hash = MULTIPLIER * hash + anArray;
- }
- return hash;
- }
-
- /**
- * Return the same value as <code>{@link Boolean#hashCode()}</code>.
- *
- * @see Boolean#hashCode()
- */
- public static int hashCode(boolean bool) {
- return bool ? 1231 : 1237;
- }
-
- /**
- * Return the same value as <code>{@link Double#hashCode()}</code>.
- *
- * @see Double#hashCode()
- */
- public static int hashCode(double dbl) {
- long bits = Double.doubleToLongBits(dbl);
- return hashCode(bits);
- }
-
- /**
- * Return the same value as <code>{@link Float#hashCode()}</code>.
- *
- * @see Float#hashCode()
- */
- public static int hashCode(float flt) {
- return Float.floatToIntBits(flt);
- }
-
- /**
- * Return the same value as <code>{@link Long#hashCode()}</code>.
- *
- * @see Long#hashCode()
- */
- public static int hashCode(long lng) {
- return (int) (lng ^ (lng >>> 32));
- }
-
- // ---------------------------------------------------------------------
- // Convenience methods for toString output
- // ---------------------------------------------------------------------
-
- /**
- * Return a String representation of an object's overall identity.
- *
- * @param obj the object (may be <code>null</code>)
- * @return the object's identity as String representation, or an empty String if the object was
- * <code>null</code>
- */
- public static String identityToString(Object obj) {
- if (obj == null) {
- return EMPTY_STRING;
- }
- return obj.getClass().getName() + "@" + getIdentityHexString(obj);
- }
-
- /**
- * Return a hex String form of an object's identity hash code.
- *
- * @param obj the object
- * @return the object's identity code in hex notation
- */
- public static String getIdentityHexString(Object obj) {
- return Integer.toHexString(System.identityHashCode(obj));
- }
-
- /**
- * Return a content-based String representation if <code>obj</code> is not <code>null</code>;
- * otherwise returns an empty String.
- *
- * <p>Differs from {@link #safeToString(Object)} in that it returns an empty String rather than
- * "null" for a <code>null</code> value.
- *
- * @param obj the object to build a display String for
- * @return a display String representation of <code>obj</code>
- * @see #safeToString(Object)
- */
- public static String getDisplayString(Object obj) {
- if (obj == null) {
- return EMPTY_STRING;
- }
- return safeToString(obj);
- }
-
- /**
- * Determine the class name for the given object.
- *
- * <p>Returns <code>"null"</code> if <code>obj</code> is <code>null</code>.
- *
- * @param obj the object to introspect (may be <code>null</code>)
- * @return the corresponding class name
- */
- public static String safeClassName(Object obj) {
- return (obj != null ? obj.getClass().getName() : NULL_STRING);
- }
-
- /**
- * Return a String representation of the specified Object.
- *
- * <p>Builds a String representation of the contents in case of an array. Returns <code>"null"
- * </code> if <code>obj</code> is <code>null</code>.
- *
- * @param obj the object to build a String representation for
- * @return a String representation of <code>obj</code>
- */
- public static String safeToString(Object obj) {
- if (obj == null) {
- return NULL_STRING;
- }
- if (obj instanceof String) {
- return (String) obj;
- }
- if (obj instanceof Object[]) {
- return safeToString((Object[]) obj);
- }
- if (obj instanceof boolean[]) {
- return safeToString((boolean[]) obj);
- }
- if (obj instanceof byte[]) {
- return safeToString((byte[]) obj);
- }
- if (obj instanceof char[]) {
- return safeToString((char[]) obj);
- }
- if (obj instanceof double[]) {
- return safeToString((double[]) obj);
- }
- if (obj instanceof float[]) {
- return safeToString((float[]) obj);
- }
- if (obj instanceof int[]) {
- return safeToString((int[]) obj);
- }
- if (obj instanceof long[]) {
- return safeToString((long[]) obj);
- }
- if (obj instanceof short[]) {
- return safeToString((short[]) obj);
- }
- String str = obj.toString();
- return (str != null ? str : EMPTY_STRING);
- }
-
- /**
- * Return a String representation of the contents of the specified array.
- *
- * <p>The String representation consists of a list of the array's elements, enclosed in curly
- * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
- * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
- * </code>.
- *
- * @param array the array to build a String representation for
- * @return a String representation of <code>array</code>
- */
- public static String safeToString(Object[] array) {
- if (array == null) {
- return NULL_STRING;
- }
- int length = array.length;
- if (length == 0) {
- return EMPTY_ARRAY;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < length; i++) {
- if (i == 0) {
- sb.append(ARRAY_START);
- } else {
- sb.append(ARRAY_ELEMENT_SEPARATOR);
- }
- sb.append(array[i]);
- }
- sb.append(ARRAY_END);
- return sb.toString();
- }
-
- /**
- * Return a String representation of the contents of the specified array.
- *
- * <p>The String representation consists of a list of the array's elements, enclosed in curly
- * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
- * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
- * </code>.
- *
- * @param array the array to build a String representation for
- * @return a String representation of <code>array</code>
- */
- public static String safeToString(boolean[] array) {
- if (array == null) {
- return NULL_STRING;
- }
- int length = array.length;
- if (length == 0) {
- return EMPTY_ARRAY;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < length; i++) {
- if (i == 0) {
- sb.append(ARRAY_START);
- } else {
- sb.append(ARRAY_ELEMENT_SEPARATOR);
- }
-
- sb.append(array[i]);
- }
- sb.append(ARRAY_END);
- return sb.toString();
- }
-
- /**
- * Return a String representation of the contents of the specified array.
- *
- * <p>The String representation consists of a list of the array's elements, enclosed in curly
- * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
- * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
- * </code>.
- *
- * @param array the array to build a String representation for
- * @return a String representation of <code>array</code>
- */
- public static String safeToString(byte[] array) {
- if (array == null) {
- return NULL_STRING;
- }
- int length = array.length;
- if (length == 0) {
- return EMPTY_ARRAY;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < length; i++) {
- if (i == 0) {
- sb.append(ARRAY_START);
- } else {
- sb.append(ARRAY_ELEMENT_SEPARATOR);
- }
- sb.append(array[i]);
- }
- sb.append(ARRAY_END);
- return sb.toString();
- }
-
- /**
- * Return a String representation of the contents of the specified array.
- *
- * <p>The String representation consists of a list of the array's elements, enclosed in curly
- * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
- * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
- * </code>.
- *
- * @param array the array to build a String representation for
- * @return a String representation of <code>array</code>
- */
- public static String safeToString(char[] array) {
- if (array == null) {
- return NULL_STRING;
- }
- int length = array.length;
- if (length == 0) {
- return EMPTY_ARRAY;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < length; i++) {
- if (i == 0) {
- sb.append(ARRAY_START);
- } else {
- sb.append(ARRAY_ELEMENT_SEPARATOR);
- }
- sb.append("'").append(array[i]).append("'");
- }
- sb.append(ARRAY_END);
- return sb.toString();
- }
-
- /**
- * Return a String representation of the contents of the specified array.
- *
- * <p>The String representation consists of a list of the array's elements, enclosed in curly
- * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
- * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
- * </code>.
- *
- * @param array the array to build a String representation for
- * @return a String representation of <code>array</code>
- */
- public static String safeToString(double[] array) {
- if (array == null) {
- return NULL_STRING;
- }
- int length = array.length;
- if (length == 0) {
- return EMPTY_ARRAY;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < length; i++) {
- if (i == 0) {
- sb.append(ARRAY_START);
- } else {
- sb.append(ARRAY_ELEMENT_SEPARATOR);
- }
-
- sb.append(array[i]);
- }
- sb.append(ARRAY_END);
- return sb.toString();
- }
-
- /**
- * Return a String representation of the contents of the specified array.
- *
- * <p>The String representation consists of a list of the array's elements, enclosed in curly
- * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
- * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
- * </code>.
- *
- * @param array the array to build a String representation for
- * @return a String representation of <code>array</code>
- */
- public static String safeToString(float[] array) {
- if (array == null) {
- return NULL_STRING;
- }
- int length = array.length;
- if (length == 0) {
- return EMPTY_ARRAY;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < length; i++) {
- if (i == 0) {
- sb.append(ARRAY_START);
- } else {
- sb.append(ARRAY_ELEMENT_SEPARATOR);
- }
-
- sb.append(array[i]);
- }
- sb.append(ARRAY_END);
- return sb.toString();
- }
-
- /**
- * Return a String representation of the contents of the specified array.
- *
- * <p>The String representation consists of a list of the array's elements, enclosed in curly
- * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
- * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
- * </code>.
- *
- * @param array the array to build a String representation for
- * @return a String representation of <code>array</code>
- */
- public static String safeToString(int[] array) {
- if (array == null) {
- return NULL_STRING;
- }
- int length = array.length;
- if (length == 0) {
- return EMPTY_ARRAY;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < length; i++) {
- if (i == 0) {
- sb.append(ARRAY_START);
- } else {
- sb.append(ARRAY_ELEMENT_SEPARATOR);
- }
- sb.append(array[i]);
- }
- sb.append(ARRAY_END);
- return sb.toString();
- }
-
- /**
- * Return a String representation of the contents of the specified array.
- *
- * <p>The String representation consists of a list of the array's elements, enclosed in curly
- * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
- * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
- * </code>.
- *
- * @param array the array to build a String representation for
- * @return a String representation of <code>array</code>
- */
- public static String safeToString(long[] array) {
- if (array == null) {
- return NULL_STRING;
- }
- int length = array.length;
- if (length == 0) {
- return EMPTY_ARRAY;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < length; i++) {
- if (i == 0) {
- sb.append(ARRAY_START);
- } else {
- sb.append(ARRAY_ELEMENT_SEPARATOR);
- }
- sb.append(array[i]);
- }
- sb.append(ARRAY_END);
- return sb.toString();
- }
-
- /**
- * Return a String representation of the contents of the specified array.
- *
- * <p>The String representation consists of a list of the array's elements, enclosed in curly
- * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
- * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
- * </code>.
- *
- * @param array the array to build a String representation for
- * @return a String representation of <code>array</code>
- */
- public static String safeToString(short[] array) {
- if (array == null) {
- return NULL_STRING;
- }
- int length = array.length;
- if (length == 0) {
- return EMPTY_ARRAY;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < length; i++) {
- if (i == 0) {
- sb.append(ARRAY_START);
- } else {
- sb.append(ARRAY_ELEMENT_SEPARATOR);
- }
- sb.append(array[i]);
- }
- sb.append(ARRAY_END);
- return sb.toString();
- }
+ private ObjectUtils() {}
+
+ private static final int INITIAL_HASH = 7;
+ private static final int MULTIPLIER = 31;
+
+ private static final String EMPTY_STRING = "";
+ private static final String NULL_STRING = "null";
+ private static final String ARRAY_START = "{";
+ private static final String ARRAY_END = "}";
+ private static final String EMPTY_ARRAY = ARRAY_START + ARRAY_END;
+ private static final String ARRAY_ELEMENT_SEPARATOR = ", ";
+
+ /**
+ * Return whether the given throwable is a checked exception: that is, neither a RuntimeException
+ * nor an Error.
+ *
+ * @param ex the throwable to check
+ * @return whether the throwable is a checked exception
+ * @see Exception
+ * @see RuntimeException
+ * @see Error
+ */
+ public static boolean isCheckedException(Throwable ex) {
+ return !(ex instanceof RuntimeException || ex instanceof Error);
+ }
+
+ /**
+ * Check whether the given exception is compatible with the exceptions declared in a throws
+ * clause.
+ *
+ * @param ex the exception to checked
+ * @param declaredExceptions the exceptions declared in the throws clause
+ * @return whether the given exception is compatible
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public static boolean isCompatibleWithThrowsClause(Throwable ex, Class[] declaredExceptions) {
+ if (!isCheckedException(ex)) {
+ return true;
+ }
+ if (declaredExceptions != null) {
+ int i = 0;
+ while (i < declaredExceptions.length) {
+ if (declaredExceptions[i].isAssignableFrom(ex.getClass())) {
+ return true;
+ }
+ i++;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Determine whether the given object is an array: either an Object array or a primitive array.
+ *
+ * @param obj the object to check
+ */
+ public static boolean isArray(Object obj) {
+ return (obj != null && obj.getClass().isArray());
+ }
+
+ /**
+ * Determine whether the given array is empty: i.e. <code>null</code> or of zero length.
+ *
+ * @param array the array to check
+ */
+ public static boolean isEmpty(Object[] array) {
+ return (array == null || array.length == 0);
+ }
+
+ /**
+ * Check whether the given array contains the given element.
+ *
+ * @param array the array to check (may be <code>null</code>, in which case the return value will
+ * always be <code>false</code>)
+ * @param element the element to check for
+ * @return whether the element has been found in the given array
+ */
+ public static boolean containsElement(Object[] array, Object element) {
+ if (array == null) {
+ return false;
+ }
+ for (Object arrayEle : array) {
+ if (safeEquals(arrayEle, element)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Check whether the given array of enum constants contains a constant with the given name,
+ * ignoring case when determining a match.
+ *
+ * @param enumValues the enum values to check, typically the product of a call to MyEnum.values()
+ * @param constant the constant name to find (must not be null or empty string)
+ * @return whether the constant has been found in the given array
+ */
+ public static boolean containsConstant(Enum<?>[] enumValues, String constant) {
+ return containsConstant(enumValues, constant, false);
+ }
+
+ /**
+ * Check whether the given array of enum constants contains a constant with the given name.
+ *
+ * @param enumValues the enum values to check, typically the product of a call to MyEnum.values()
+ * @param constant the constant name to find (must not be null or empty string)
+ * @param caseSensitive whether case is significant in determining a match
+ * @return whether the constant has been found in the given array
+ */
+ public static boolean containsConstant(
+ Enum<?>[] enumValues, String constant, boolean caseSensitive) {
+ for (Enum<?> candidate : enumValues) {
+ if (caseSensitive
+ ? candidate.toString().equals(constant)
+ : candidate.toString().equalsIgnoreCase(constant)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Case insensitive alternative to {@link Enum#valueOf(Class, String)}.
+ *
+ * @param <E> the concrete Enum type
+ * @param enumValues the array of all Enum constants in question, usually per Enum.values()
+ * @param constant the constant to get the enum value of
+ * @throws IllegalArgumentException if the given constant is not found in the given array of enum
+ * values. Use {@link #containsConstant(Enum[], String)} as a guard to avoid this exception.
+ */
+ public static <E extends Enum<?>> E caseInsensitiveValueOf(E[] enumValues, String constant) {
+ for (E candidate : enumValues) {
+ if (candidate.toString().equalsIgnoreCase(constant)) {
+ return candidate;
+ }
+ }
+ throw new IllegalArgumentException(
+ String.format(
+ "constant [%s] does not exist in enum type %s",
+ constant, enumValues.getClass().getComponentType().getName()));
+ }
+
+ /**
+ * Append the given object to the given array, returning a new array consisting of the input array
+ * contents plus the given object.
+ *
+ * @param array the array to append to (can be <code>null</code>)
+ * @param obj the object to append
+ * @return the new array (of the same component type; never <code>null</code>)
+ */
+ public static <A, O extends A> A[] addObjectToArray(A[] array, O obj) {
+ Class<?> compType = Object.class;
+ if (array != null) {
+ compType = array.getClass().getComponentType();
+ } else if (obj != null) {
+ compType = obj.getClass();
+ }
+ int newArrLength = (array != null ? array.length + 1 : 1);
+ @SuppressWarnings("unchecked")
+ A[] newArr = (A[]) Array.newInstance(compType, newArrLength);
+ if (array != null) {
+ System.arraycopy(array, 0, newArr, 0, array.length);
+ }
+ newArr[newArr.length - 1] = obj;
+ return newArr;
+ }
+
+ /**
+ * Convert the given array (which may be a primitive array) to an object array (if necessary of
+ * primitive wrapper objects).
+ *
+ * <p>A <code>null</code> source value will be converted to an empty Object array.
+ *
+ * @param source the (potentially primitive) array
+ * @return the corresponding object array (never <code>null</code>)
+ * @throws IllegalArgumentException if the parameter is not an array
+ */
+ public static Object[] toObjectArray(Object source) {
+ if (source instanceof Object[]) {
+ return (Object[]) source;
+ }
+ if (source == null) {
+ return new Object[0];
+ }
+ if (!source.getClass().isArray()) {
+ throw new IllegalArgumentException("Source is not an array: " + source);
+ }
+ int length = Array.getLength(source);
+ if (length == 0) {
+ return new Object[0];
+ }
+ @SuppressWarnings("rawtypes")
+ Class wrapperType = Array.get(source, 0).getClass();
+ Object[] newArray = (Object[]) Array.newInstance(wrapperType, length);
+ for (int i = 0; i < length; i++) {
+ newArray[i] = Array.get(source, i);
+ }
+ return newArray;
+ }
+
+ // ---------------------------------------------------------------------
+ // Convenience methods for content-based equality/hash-code handling
+ // ---------------------------------------------------------------------
+
+ /**
+ * Determine if the given objects are equal, returning <code>true</code> if both are <code>null
+ * </code> or <code>false</code> if only one is <code>null</code>.
+ *
+ * <p>Compares arrays with <code>Arrays.equals</code>, performing an equality check based on the
+ * array elements rather than the array reference.
+ *
+ * @param o1 first Object to compare
+ * @param o2 second Object to compare
+ * @return whether the given objects are equal
+ * @see Arrays#equals
+ */
+ public static boolean safeEquals(Object o1, Object o2) {
+ if (o1 == null || o2 == null) {
+ return false;
+ }
+
+ if (o1 == o2) {
+ return true;
+ }
+
+ if (o1.equals(o2)) {
+ return true;
+ }
+ if (o1.getClass().isArray() && o2.getClass().isArray()) {
+ if (o1 instanceof Object[] && o2 instanceof Object[]) {
+ return Arrays.equals((Object[]) o1, (Object[]) o2);
+ }
+ if (o1 instanceof boolean[] && o2 instanceof boolean[]) {
+ return Arrays.equals((boolean[]) o1, (boolean[]) o2);
+ }
+ if (o1 instanceof byte[] && o2 instanceof byte[]) {
+ return Arrays.equals((byte[]) o1, (byte[]) o2);
+ }
+ if (o1 instanceof char[] && o2 instanceof char[]) {
+ return Arrays.equals((char[]) o1, (char[]) o2);
+ }
+ if (o1 instanceof double[] && o2 instanceof double[]) {
+ return Arrays.equals((double[]) o1, (double[]) o2);
+ }
+ if (o1 instanceof float[] && o2 instanceof float[]) {
+ return Arrays.equals((float[]) o1, (float[]) o2);
+ }
+ if (o1 instanceof int[] && o2 instanceof int[]) {
+ return Arrays.equals((int[]) o1, (int[]) o2);
+ }
+ if (o1 instanceof long[] && o2 instanceof long[]) {
+ return Arrays.equals((long[]) o1, (long[]) o2);
+ }
+ if (o1 instanceof short[] && o2 instanceof short[]) {
+ return Arrays.equals((short[]) o1, (short[]) o2);
+ }
+ }
+ return false;
+ }
+
+ public static boolean safeTrimEquals(Object o1, Object o2) {
+ boolean equals = safeEquals(o1, o2);
+ if (!equals) {
+ if (o1 != null && o2 != null) {
+ if (o1 instanceof String && o2 instanceof String) {
+ return o1.toString().trim().equals(o2.toString().trim());
+ }
+ }
+ }
+ return equals;
+ }
+
+ /**
+ * Return as hash code for the given object; typically the value of <code>
+ * {@link Object#hashCode()}</code>. If the object is an array, this method will delegate to any
+ * of the <code>safeHashCode</code> methods for arrays in this class. If the object is <code>null
+ * </code>, this method returns 0.
+ *
+ * @see #safeHashCode(Object[])
+ * @see #safeHashCode(boolean[])
+ * @see #safeHashCode(byte[])
+ * @see #safeHashCode(char[])
+ * @see #safeHashCode(double[])
+ * @see #safeHashCode(float[])
+ * @see #safeHashCode(int[])
+ * @see #safeHashCode(long[])
+ * @see #safeHashCode(short[])
+ */
+ public static int safeHashCode(Object obj) {
+ if (obj == null) {
+ return 0;
+ }
+ if (obj.getClass().isArray()) {
+ if (obj instanceof Object[]) {
+ return safeHashCode((Object[]) obj);
+ }
+ if (obj instanceof boolean[]) {
+ return safeHashCode((boolean[]) obj);
+ }
+ if (obj instanceof byte[]) {
+ return safeHashCode((byte[]) obj);
+ }
+ if (obj instanceof char[]) {
+ return safeHashCode((char[]) obj);
+ }
+ if (obj instanceof double[]) {
+ return safeHashCode((double[]) obj);
+ }
+ if (obj instanceof float[]) {
+ return safeHashCode((float[]) obj);
+ }
+ if (obj instanceof int[]) {
+ return safeHashCode((int[]) obj);
+ }
+ if (obj instanceof long[]) {
+ return safeHashCode((long[]) obj);
+ }
+ if (obj instanceof short[]) {
+ return safeHashCode((short[]) obj);
+ }
+ }
+ return obj.hashCode();
+ }
+
+ /**
+ * Return a hash code based on the contents of the specified array. If <code>array</code> is
+ * <code>null</code>, this method returns 0.
+ */
+ public static int safeHashCode(Object[] array) {
+ if (array == null) {
+ return 0;
+ }
+ int hash = INITIAL_HASH;
+ for (Object anArray : array) {
+ hash = MULTIPLIER * hash + safeHashCode(anArray);
+ }
+ return hash;
+ }
+
+ /**
+ * Return a hash code based on the contents of the specified array. If <code>array</code> is
+ * <code>null</code>, this method returns 0.
+ */
+ public static int safeHashCode(boolean[] array) {
+ if (array == null) {
+ return 0;
+ }
+ int hash = INITIAL_HASH;
+ for (boolean anArray : array) {
+ hash = MULTIPLIER * hash + hashCode(anArray);
+ }
+ return hash;
+ }
+
+ /**
+ * Return a hash code based on the contents of the specified array. If <code>array</code> is
+ * <code>null</code>, this method returns 0.
+ */
+ public static int safeHashCode(byte[] array) {
+ if (array == null) {
+ return 0;
+ }
+ int hash = INITIAL_HASH;
+ for (byte anArray : array) {
+ hash = MULTIPLIER * hash + anArray;
+ }
+ return hash;
+ }
+
+ /**
+ * Return a hash code based on the contents of the specified array. If <code>array</code> is
+ * <code>null</code>, this method returns 0.
+ */
+ public static int safeHashCode(char[] array) {
+ if (array == null) {
+ return 0;
+ }
+ int hash = INITIAL_HASH;
+ for (char anArray : array) {
+ hash = MULTIPLIER * hash + anArray;
+ }
+ return hash;
+ }
+
+ /**
+ * Return a hash code based on the contents of the specified array. If <code>array</code> is
+ * <code>null</code>, this method returns 0.
+ */
+ public static int safeHashCode(double[] array) {
+ if (array == null) {
+ return 0;
+ }
+ int hash = INITIAL_HASH;
+ for (double anArray : array) {
+ hash = MULTIPLIER * hash + hashCode(anArray);
+ }
+ return hash;
+ }
+
+ /**
+ * Return a hash code based on the contents of the specified array. If <code>array</code> is
+ * <code>null</code>, this method returns 0.
+ */
+ public static int safeHashCode(float[] array) {
+ if (array == null) {
+ return 0;
+ }
+ int hash = INITIAL_HASH;
+ for (float anArray : array) {
+ hash = MULTIPLIER * hash + hashCode(anArray);
+ }
+ return hash;
+ }
+
+ /**
+ * Return a hash code based on the contents of the specified array. If <code>array</code> is
+ * <code>null</code>, this method returns 0.
+ */
+ public static int safeHashCode(int[] array) {
+ if (array == null) {
+ return 0;
+ }
+ int hash = INITIAL_HASH;
+ for (int anArray : array) {
+ hash = MULTIPLIER * hash + anArray;
+ }
+ return hash;
+ }
+
+ /**
+ * Return a hash code based on the contents of the specified array. If <code>array</code> is
+ * <code>null</code>, this method returns 0.
+ */
+ public static int safeHashCode(long[] array) {
+ if (array == null) {
+ return 0;
+ }
+ int hash = INITIAL_HASH;
+ for (long anArray : array) {
+ hash = MULTIPLIER * hash + hashCode(anArray);
+ }
+ return hash;
+ }
+
+ /**
+ * Return a hash code based on the contents of the specified array. If <code>array</code> is
+ * <code>null</code>, this method returns 0.
+ */
+ public static int safeHashCode(short[] array) {
+ if (array == null) {
+ return 0;
+ }
+ int hash = INITIAL_HASH;
+ for (short anArray : array) {
+ hash = MULTIPLIER * hash + anArray;
+ }
+ return hash;
+ }
+
+ /**
+ * Return the same value as <code>{@link Boolean#hashCode()}</code>.
+ *
+ * @see Boolean#hashCode()
+ */
+ public static int hashCode(boolean bool) {
+ return bool ? 1231 : 1237;
+ }
+
+ /**
+ * Return the same value as <code>{@link Double#hashCode()}</code>.
+ *
+ * @see Double#hashCode()
+ */
+ public static int hashCode(double dbl) {
+ long bits = Double.doubleToLongBits(dbl);
+ return hashCode(bits);
+ }
+
+ /**
+ * Return the same value as <code>{@link Float#hashCode()}</code>.
+ *
+ * @see Float#hashCode()
+ */
+ public static int hashCode(float flt) {
+ return Float.floatToIntBits(flt);
+ }
+
+ /**
+ * Return the same value as <code>{@link Long#hashCode()}</code>.
+ *
+ * @see Long#hashCode()
+ */
+ public static int hashCode(long lng) {
+ return (int) (lng ^ (lng >>> 32));
+ }
+
+ // ---------------------------------------------------------------------
+ // Convenience methods for toString output
+ // ---------------------------------------------------------------------
+
+ /**
+ * Return a String representation of an object's overall identity.
+ *
+ * @param obj the object (may be <code>null</code>)
+ * @return the object's identity as String representation, or an empty String if the object was
+ * <code>null</code>
+ */
+ public static String identityToString(Object obj) {
+ if (obj == null) {
+ return EMPTY_STRING;
+ }
+ return obj.getClass().getName() + "@" + getIdentityHexString(obj);
+ }
+
+ /**
+ * Return a hex String form of an object's identity hash code.
+ *
+ * @param obj the object
+ * @return the object's identity code in hex notation
+ */
+ public static String getIdentityHexString(Object obj) {
+ return Integer.toHexString(System.identityHashCode(obj));
+ }
+
+ /**
+ * Return a content-based String representation if <code>obj</code> is not <code>null</code>;
+ * otherwise returns an empty String.
+ *
+ * <p>Differs from {@link #safeToString(Object)} in that it returns an empty String rather than
+ * "null" for a <code>null</code> value.
+ *
+ * @param obj the object to build a display String for
+ * @return a display String representation of <code>obj</code>
+ * @see #safeToString(Object)
+ */
+ public static String getDisplayString(Object obj) {
+ if (obj == null) {
+ return EMPTY_STRING;
+ }
+ return safeToString(obj);
+ }
+
+ /**
+ * Determine the class name for the given object.
+ *
+ * <p>Returns <code>"null"</code> if <code>obj</code> is <code>null</code>.
+ *
+ * @param obj the object to introspect (may be <code>null</code>)
+ * @return the corresponding class name
+ */
+ public static String safeClassName(Object obj) {
+ return (obj != null ? obj.getClass().getName() : NULL_STRING);
+ }
+
+ /**
+ * Return a String representation of the specified Object.
+ *
+ * <p>Builds a String representation of the contents in case of an array. Returns <code>"null"
+ * </code> if <code>obj</code> is <code>null</code>.
+ *
+ * @param obj the object to build a String representation for
+ * @return a String representation of <code>obj</code>
+ */
+ public static String safeToString(Object obj) {
+ if (obj == null) {
+ return NULL_STRING;
+ }
+ if (obj instanceof String) {
+ return (String) obj;
+ }
+ if (obj instanceof Object[]) {
+ return safeToString((Object[]) obj);
+ }
+ if (obj instanceof boolean[]) {
+ return safeToString((boolean[]) obj);
+ }
+ if (obj instanceof byte[]) {
+ return safeToString((byte[]) obj);
+ }
+ if (obj instanceof char[]) {
+ return safeToString((char[]) obj);
+ }
+ if (obj instanceof double[]) {
+ return safeToString((double[]) obj);
+ }
+ if (obj instanceof float[]) {
+ return safeToString((float[]) obj);
+ }
+ if (obj instanceof int[]) {
+ return safeToString((int[]) obj);
+ }
+ if (obj instanceof long[]) {
+ return safeToString((long[]) obj);
+ }
+ if (obj instanceof short[]) {
+ return safeToString((short[]) obj);
+ }
+ String str = obj.toString();
+ return (str != null ? str : EMPTY_STRING);
+ }
+
+ /**
+ * Return a String representation of the contents of the specified array.
+ *
+ * <p>The String representation consists of a list of the array's elements, enclosed in curly
+ * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
+ * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
+ * </code>.
+ *
+ * @param array the array to build a String representation for
+ * @return a String representation of <code>array</code>
+ */
+ public static String safeToString(Object[] array) {
+ if (array == null) {
+ return NULL_STRING;
+ }
+ int length = array.length;
+ if (length == 0) {
+ return EMPTY_ARRAY;
+ }
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ if (i == 0) {
+ sb.append(ARRAY_START);
+ } else {
+ sb.append(ARRAY_ELEMENT_SEPARATOR);
+ }
+ sb.append(array[i]);
+ }
+ sb.append(ARRAY_END);
+ return sb.toString();
+ }
+
+ /**
+ * Return a String representation of the contents of the specified array.
+ *
+ * <p>The String representation consists of a list of the array's elements, enclosed in curly
+ * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
+ * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
+ * </code>.
+ *
+ * @param array the array to build a String representation for
+ * @return a String representation of <code>array</code>
+ */
+ public static String safeToString(boolean[] array) {
+ if (array == null) {
+ return NULL_STRING;
+ }
+ int length = array.length;
+ if (length == 0) {
+ return EMPTY_ARRAY;
+ }
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ if (i == 0) {
+ sb.append(ARRAY_START);
+ } else {
+ sb.append(ARRAY_ELEMENT_SEPARATOR);
+ }
+
+ sb.append(array[i]);
+ }
+ sb.append(ARRAY_END);
+ return sb.toString();
+ }
+
+ /**
+ * Return a String representation of the contents of the specified array.
+ *
+ * <p>The String representation consists of a list of the array's elements, enclosed in curly
+ * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
+ * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
+ * </code>.
+ *
+ * @param array the array to build a String representation for
+ * @return a String representation of <code>array</code>
+ */
+ public static String safeToString(byte[] array) {
+ if (array == null) {
+ return NULL_STRING;
+ }
+ int length = array.length;
+ if (length == 0) {
+ return EMPTY_ARRAY;
+ }
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ if (i == 0) {
+ sb.append(ARRAY_START);
+ } else {
+ sb.append(ARRAY_ELEMENT_SEPARATOR);
+ }
+ sb.append(array[i]);
+ }
+ sb.append(ARRAY_END);
+ return sb.toString();
+ }
+
+ /**
+ * Return a String representation of the contents of the specified array.
+ *
+ * <p>The String representation consists of a list of the array's elements, enclosed in curly
+ * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
+ * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
+ * </code>.
+ *
+ * @param array the array to build a String representation for
+ * @return a String representation of <code>array</code>
+ */
+ public static String safeToString(char[] array) {
+ if (array == null) {
+ return NULL_STRING;
+ }
+ int length = array.length;
+ if (length == 0) {
+ return EMPTY_ARRAY;
+ }
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ if (i == 0) {
+ sb.append(ARRAY_START);
+ } else {
+ sb.append(ARRAY_ELEMENT_SEPARATOR);
+ }
+ sb.append("'").append(array[i]).append("'");
+ }
+ sb.append(ARRAY_END);
+ return sb.toString();
+ }
+
+ /**
+ * Return a String representation of the contents of the specified array.
+ *
+ * <p>The String representation consists of a list of the array's elements, enclosed in curly
+ * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
+ * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
+ * </code>.
+ *
+ * @param array the array to build a String representation for
+ * @return a String representation of <code>array</code>
+ */
+ public static String safeToString(double[] array) {
+ if (array == null) {
+ return NULL_STRING;
+ }
+ int length = array.length;
+ if (length == 0) {
+ return EMPTY_ARRAY;
+ }
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ if (i == 0) {
+ sb.append(ARRAY_START);
+ } else {
+ sb.append(ARRAY_ELEMENT_SEPARATOR);
+ }
+
+ sb.append(array[i]);
+ }
+ sb.append(ARRAY_END);
+ return sb.toString();
+ }
+
+ /**
+ * Return a String representation of the contents of the specified array.
+ *
+ * <p>The String representation consists of a list of the array's elements, enclosed in curly
+ * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
+ * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
+ * </code>.
+ *
+ * @param array the array to build a String representation for
+ * @return a String representation of <code>array</code>
+ */
+ public static String safeToString(float[] array) {
+ if (array == null) {
+ return NULL_STRING;
+ }
+ int length = array.length;
+ if (length == 0) {
+ return EMPTY_ARRAY;
+ }
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ if (i == 0) {
+ sb.append(ARRAY_START);
+ } else {
+ sb.append(ARRAY_ELEMENT_SEPARATOR);
+ }
+
+ sb.append(array[i]);
+ }
+ sb.append(ARRAY_END);
+ return sb.toString();
+ }
+
+ /**
+ * Return a String representation of the contents of the specified array.
+ *
+ * <p>The String representation consists of a list of the array's elements, enclosed in curly
+ * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
+ * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
+ * </code>.
+ *
+ * @param array the array to build a String representation for
+ * @return a String representation of <code>array</code>
+ */
+ public static String safeToString(int[] array) {
+ if (array == null) {
+ return NULL_STRING;
+ }
+ int length = array.length;
+ if (length == 0) {
+ return EMPTY_ARRAY;
+ }
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ if (i == 0) {
+ sb.append(ARRAY_START);
+ } else {
+ sb.append(ARRAY_ELEMENT_SEPARATOR);
+ }
+ sb.append(array[i]);
+ }
+ sb.append(ARRAY_END);
+ return sb.toString();
+ }
+
+ /**
+ * Return a String representation of the contents of the specified array.
+ *
+ * <p>The String representation consists of a list of the array's elements, enclosed in curly
+ * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
+ * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
+ * </code>.
+ *
+ * @param array the array to build a String representation for
+ * @return a String representation of <code>array</code>
+ */
+ public static String safeToString(long[] array) {
+ if (array == null) {
+ return NULL_STRING;
+ }
+ int length = array.length;
+ if (length == 0) {
+ return EMPTY_ARRAY;
+ }
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ if (i == 0) {
+ sb.append(ARRAY_START);
+ } else {
+ sb.append(ARRAY_ELEMENT_SEPARATOR);
+ }
+ sb.append(array[i]);
+ }
+ sb.append(ARRAY_END);
+ return sb.toString();
+ }
+
+ /**
+ * Return a String representation of the contents of the specified array.
+ *
+ * <p>The String representation consists of a list of the array's elements, enclosed in curly
+ * braces (<code>"{}"</code>). Adjacent elements are separated by the characters <code>", "</code>
+ * (a comma followed by a space). Returns <code>"null"</code> if <code>array</code> is <code>null
+ * </code>.
+ *
+ * @param array the array to build a String representation for
+ * @return a String representation of <code>array</code>
+ */
+ public static String safeToString(short[] array) {
+ if (array == null) {
+ return NULL_STRING;
+ }
+ int length = array.length;
+ if (length == 0) {
+ return EMPTY_ARRAY;
+ }
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ if (i == 0) {
+ sb.append(ARRAY_START);
+ } else {
+ sb.append(ARRAY_ELEMENT_SEPARATOR);
+ }
+ sb.append(array[i]);
+ }
+ sb.append(ARRAY_END);
+ return sb.toString();
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/ShaHashUtils.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/ShaHashUtils.java
index bf7557d55..5a1570835 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/ShaHashUtils.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/ShaHashUtils.java
@@ -24,42 +24,39 @@ import java.util.Random;
public final class ShaHashUtils {
- public static final int DEFAULT_SALT_LENGTH = 26;
-
- private ShaHashUtils() {
-
+ public static final int DEFAULT_SALT_LENGTH = 26;
+
+ private ShaHashUtils() {}
+
+ /**
+ * encrypt user password
+ *
+ * @param salt
+ * @param password
+ * @return
+ */
+ public static String encrypt(String salt, String password) {
+ return new Sha256Hash(password, ByteSource.Util.bytes(salt), 1024).toHex();
+ }
+
+ public static String getRandomSalt() {
+ return getRandomSalt(DEFAULT_SALT_LENGTH);
+ }
+
+ /**
+ * get random salt
+ *
+ * @param length
+ * @return
+ */
+ public static String getRandomSalt(int length) {
+ String base = "abcdefghijklmnopqrstuvwxyz0123456789";
+ Random random = new Random();
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ int number = random.nextInt(base.length());
+ builder.append(base.charAt(number));
}
-
- /**
- * encrypt user password
- *
- * @param salt
- * @param password
- * @return
- */
- public static String encrypt(String salt, String password) {
- return new Sha256Hash(password, ByteSource.Util.bytes(salt), 1024).toHex();
- }
-
- public static String getRandomSalt() {
- return getRandomSalt(DEFAULT_SALT_LENGTH);
- }
-
- /**
- * get random salt
- *
- * @param length
- * @return
- */
- public static String getRandomSalt(int length) {
- String base = "abcdefghijklmnopqrstuvwxyz0123456789";
- Random random = new Random();
- StringBuilder builder = new StringBuilder();
- for (int i = 0; i < length; i++) {
- int number = random.nextInt(base.length());
- builder.append(base.charAt(number));
- }
- return builder.toString();
- }
-
+ return builder.toString();
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/SpringContextUtils.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/SpringContextUtils.java
index 0af101990..4c05bc778 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/SpringContextUtils.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/SpringContextUtils.java
@@ -25,34 +25,34 @@ import org.springframework.stereotype.Component;
@Component
public class SpringContextUtils implements ApplicationContextAware {
- private static ApplicationContext applicationContext;
+ private static ApplicationContext applicationContext;
- @Override
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
- SpringContextUtils.applicationContext = applicationContext;
- }
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ SpringContextUtils.applicationContext = applicationContext;
+ }
- public static Object getBean(String name) {
- return applicationContext.getBean(name);
- }
+ public static Object getBean(String name) {
+ return applicationContext.getBean(name);
+ }
- public static <T> T getBean(Class<T> clazz) {
- return applicationContext.getBean(clazz);
- }
+ public static <T> T getBean(Class<T> clazz) {
+ return applicationContext.getBean(clazz);
+ }
- public static <T> T getBean(String name, Class<T> requiredType) {
- return applicationContext.getBean(name, requiredType);
- }
+ public static <T> T getBean(String name, Class<T> requiredType) {
+ return applicationContext.getBean(name, requiredType);
+ }
- public static boolean containsBean(String name) {
- return applicationContext.containsBean(name);
- }
+ public static boolean containsBean(String name) {
+ return applicationContext.containsBean(name);
+ }
- public static boolean isSingleton(String name) {
- return applicationContext.isSingleton(name);
- }
+ public static boolean isSingleton(String name) {
+ return applicationContext.isSingleton(name);
+ }
- public static Class<?> getType(String name) {
- return applicationContext.getType(name);
- }
+ public static Class<?> getType(String name) {
+ return applicationContext.getType(name);
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/VueRouterUtils.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/VueRouterUtils.java
index 118956001..b62f1f809 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/VueRouterUtils.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/VueRouterUtils.java
@@ -25,98 +25,99 @@ import java.util.List;
public final class VueRouterUtils {
- private VueRouterUtils() {
- }
+ private VueRouterUtils() {}
- private static final String TOP_NODE_ID = "0";
+ private static final String TOP_NODE_ID = "0";
- /**
- * build menu or department tree
- *
- * @param nodes nodes
- * @param <T> <T>
- * @return <T> Tree<T>
- */
- public static <T> RouterTree<T> buildRouterTree(List<RouterTree<T>> nodes) {
- if (nodes == null) {
- return null;
- }
- List<RouterTree<T>> topNodes = new ArrayList<>();
- nodes.forEach(node -> {
- String pid = node.getParentId();
- if (pid == null || TOP_NODE_ID.equals(pid)) {
- topNodes.add(node);
- return;
- }
- for (RouterTree<T> n : nodes) {
- String id = n.getId();
- if (id != null && id.equals(pid)) {
- if (n.getChildren() == null) {
- n.initChildren();
- }
- n.getChildren().add(node);
- node.setHasParent(true);
- n.setHasChildren(true);
- n.setHasParent(true);
- return;
- }
- }
- if (topNodes.isEmpty()) {
- topNodes.add(node);
+ /**
+ * build menu or department tree
+ *
+ * @param nodes nodes
+ * @param <T> <T>
+ * @return <T> Tree<T>
+ */
+ public static <T> RouterTree<T> buildRouterTree(List<RouterTree<T>> nodes) {
+ if (nodes == null) {
+ return null;
+ }
+ List<RouterTree<T>> topNodes = new ArrayList<>();
+ nodes.forEach(
+ node -> {
+ String pid = node.getParentId();
+ if (pid == null || TOP_NODE_ID.equals(pid)) {
+ topNodes.add(node);
+ return;
+ }
+ for (RouterTree<T> n : nodes) {
+ String id = n.getId();
+ if (id != null && id.equals(pid)) {
+ if (n.getChildren() == null) {
+ n.initChildren();
+ }
+ n.getChildren().add(node);
+ node.setHasParent(true);
+ n.setHasChildren(true);
+ n.setHasParent(true);
+ return;
}
+ }
+ if (topNodes.isEmpty()) {
+ topNodes.add(node);
+ }
});
- RouterTree<T> root = new RouterTree<>();
- root.setId("0");
- root.setParentId("");
- root.setHasParent(false);
- root.setHasChildren(true);
- root.setChildren(topNodes);
- root.setText("root");
- return root;
- }
+ RouterTree<T> root = new RouterTree<>();
+ root.setId("0");
+ root.setParentId("");
+ root.setHasParent(false);
+ root.setHasChildren(true);
+ root.setChildren(topNodes);
+ root.setText("root");
+ return root;
+ }
- /**
- * build vue router
- *
- * @param routes routes
- * @param <T> T
- * @return ArrayList<VueRouter < T>>
- */
- public static <T> ArrayList<VueRouter<T>> buildVueRouter(List<VueRouter<T>> routes) {
- if (routes == null) {
- return null;
- }
- List<VueRouter<T>> topRoutes = new ArrayList<>();
- routes.forEach(route -> {
- String parentId = route.getParentId();
- if (parentId == null || TOP_NODE_ID.equals(parentId)) {
- topRoutes.add(route);
- return;
- }
- for (VueRouter<T> parent : routes) {
- String id = parent.getId();
- if (parentId.equals(id)) {
- if (parent.getChildren() == null) {
- parent.initChildren();
- }
- parent.getChildren().add(route);
- parent.setHasChildren(true);
- route.setHasParent(true);
- parent.setHasParent(true);
- return;
- }
+ /**
+ * build vue router
+ *
+ * @param routes routes
+ * @param <T> T
+ * @return ArrayList<VueRouter < T>>
+ */
+ public static <T> ArrayList<VueRouter<T>> buildVueRouter(List<VueRouter<T>> routes) {
+ if (routes == null) {
+ return null;
+ }
+ List<VueRouter<T>> topRoutes = new ArrayList<>();
+ routes.forEach(
+ route -> {
+ String parentId = route.getParentId();
+ if (parentId == null || TOP_NODE_ID.equals(parentId)) {
+ topRoutes.add(route);
+ return;
+ }
+ for (VueRouter<T> parent : routes) {
+ String id = parent.getId();
+ if (parentId.equals(id)) {
+ if (parent.getChildren() == null) {
+ parent.initChildren();
+ }
+ parent.getChildren().add(route);
+ parent.setHasChildren(true);
+ route.setHasParent(true);
+ parent.setHasParent(true);
+ return;
}
+ }
});
- ArrayList<VueRouter<T>> list = new ArrayList<>();
- VueRouter<T> root = new VueRouter<>();
- root.setName("Root");
- root.setComponent("BasicView");
- root.setPath("/");
- root.setChildren(topRoutes);
- list.add(root);
+ ArrayList<VueRouter<T>> list = new ArrayList<>();
+ VueRouter<T> root = new VueRouter<>();
+ root.setName("Root");
+ root.setComponent("BasicView");
+ root.setPath("/");
+ root.setChildren(topRoutes);
+ list.add(root);
- return list;
- }
+ return list;
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/WebUtils.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/WebUtils.java
index a08204784..f88036858 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/WebUtils.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/WebUtils.java
@@ -27,99 +27,96 @@ import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.util.stream.IntStream;
-/**
- * Web Utils
- */
+/** Web Utils */
@Slf4j
public final class WebUtils {
- private WebUtils() {
-
+ private WebUtils() {}
+
+ /**
+ * token encrypt
+ *
+ * @param token token
+ * @return encrypt token
+ */
+ public static String encryptToken(String token) {
+ try {
+ EncryptUtils encryptUtils = new EncryptUtils(Constant.TOKEN_CACHE_PREFIX);
+ return encryptUtils.encrypt(token);
+ } catch (Exception e) {
+ log.info("token encrypt failed: ", e);
+ return null;
}
-
- /**
- * token encrypt
- *
- * @param token token
- * @return encrypt token
- */
- public static String encryptToken(String token) {
- try {
- EncryptUtils encryptUtils = new EncryptUtils(Constant.TOKEN_CACHE_PREFIX);
- return encryptUtils.encrypt(token);
- } catch (Exception e) {
- log.info("token encrypt failed: ", e);
- return null;
- }
+ }
+
+ /**
+ * token decrypt
+ *
+ * @param encryptToken encryptToken
+ * @return decrypt token
+ */
+ public static String decryptToken(String encryptToken) {
+ try {
+ EncryptUtils encryptUtils = new EncryptUtils(Constant.TOKEN_CACHE_PREFIX);
+ return encryptUtils.decrypt(encryptToken);
+ } catch (Exception e) {
+ log.info("token decrypt failed: ", e);
+ return null;
}
-
- /**
- * token decrypt
- *
- * @param encryptToken encryptToken
- * @return decrypt token
- */
- public static String decryptToken(String encryptToken) {
- try {
- EncryptUtils encryptUtils = new EncryptUtils(Constant.TOKEN_CACHE_PREFIX);
- return encryptUtils.decrypt(encryptToken);
- } catch (Exception e) {
- log.info("token decrypt failed: ", e);
- return null;
- }
+ }
+
+ /**
+ * camel to underscore
+ *
+ * @param value value
+ * @return underscore
+ */
+ public static String camelToUnderscore(String value) {
+ if (StringUtils.isBlank(value) || value.contains("_")) {
+ return value;
}
-
- /**
- * camel to underscore
- *
- * @param value value
- * @return underscore
- */
- public static String camelToUnderscore(String value) {
- if (StringUtils.isBlank(value) || value.contains("_")) {
- return value;
- }
- String[] arr = StringUtils.splitByCharacterTypeCamelCase(value);
- if (arr.length == 0) {
- return value;
- }
- StringBuilder result = new StringBuilder();
- IntStream.range(0, arr.length).forEach(i -> {
- if (i != arr.length - 1) {
+ String[] arr = StringUtils.splitByCharacterTypeCamelCase(value);
+ if (arr.length == 0) {
+ return value;
+ }
+ StringBuilder result = new StringBuilder();
+ IntStream.range(0, arr.length)
+ .forEach(
+ i -> {
+ if (i != arr.length - 1) {
result.append(arr[i]).append(StringPool.UNDERSCORE);
- } else {
+ } else {
result.append(arr[i]);
- }
- });
- return StringUtils.lowerCase(result.toString());
- }
-
- public static String getAppHome() {
- return System.getProperty(ConfigConst.KEY_APP_HOME());
- }
-
- public static File getAppDir(String dir) {
- return new File(getAppHome(), dir);
- }
-
- public static File getAppTempDir() {
- return getAppDir("temp");
- }
-
- public static File getAppLibDir() {
- return getAppDir("lib");
- }
-
- public static File getAppPluginsDir() {
- return getAppDir("plugins");
- }
-
- public static File getAppClientDir() {
- return getAppDir("client");
- }
-
- public static File getAppConfDir() {
- return getAppDir("conf");
- }
+ }
+ });
+ return StringUtils.lowerCase(result.toString());
+ }
+
+ public static String getAppHome() {
+ return System.getProperty(ConfigConst.KEY_APP_HOME());
+ }
+
+ public static File getAppDir(String dir) {
+ return new File(getAppHome(), dir);
+ }
+
+ public static File getAppTempDir() {
+ return getAppDir("temp");
+ }
+
+ public static File getAppLibDir() {
+ return getAppDir("lib");
+ }
+
+ public static File getAppPluginsDir() {
+ return getAppDir("plugins");
+ }
+
+ public static File getAppClientDir() {
+ return getAppDir("client");
+ }
+
+ public static File getAppConfDir() {
+ return getAppDir("conf");
+ }
}
-
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/annotation/ApiAccess.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/annotation/ApiAccess.java
index 5c95b9e2c..5326c4dd8 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/annotation/ApiAccess.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/annotation/ApiAccess.java
@@ -25,6 +25,5 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ApiAccess {
- boolean value() default true;
-
+ boolean value() default true;
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/annotation/RefreshCache.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/annotation/RefreshCache.java
index 451867c9d..d4cc55ab9 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/annotation/RefreshCache.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/annotation/RefreshCache.java
@@ -24,5 +24,4 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
-public @interface RefreshCache {
-}
+public @interface RefreshCache {}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/aspect/StreamParkConsoleAspect.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/aspect/StreamParkConsoleAspect.java
index 9184e9474..751521fcb 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/aspect/StreamParkConsoleAspect.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/aspect/StreamParkConsoleAspect.java
@@ -35,32 +35,32 @@ import java.lang.reflect.Method;
@Aspect
public class StreamParkConsoleAspect {
- @Pointcut("@annotation(org.apache.streampark.console.core.annotation.RefreshCache)")
- public void refreshCache() {
- }
+ @Pointcut("@annotation(org.apache.streampark.console.core.annotation.RefreshCache)")
+ public void refreshCache() {}
- @Around("refreshCache()")
- public Object refreshCache(ProceedingJoinPoint joinPoint) throws Throwable {
- MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
- log.debug("refreshCache aspect, method:{}", methodSignature.getName());
- Object[] args = joinPoint.getArgs();
- Object param = args[0];
- Long appId;
- if (param instanceof Application) {
- appId = ((Application) param).getId();
- } else {
- Method method = param.getClass().getDeclaredMethod("getAppId");
- method.setAccessible(true);
- appId = (Long) method.invoke(param, null);
- }
- return FlinkTrackingTask.refreshTracking(appId, () -> {
- try {
- return joinPoint.proceed();
- } catch (Throwable throwable) {
- throwable.printStackTrace();
- }
- return null;
- });
+ @Around("refreshCache()")
+ public Object refreshCache(ProceedingJoinPoint joinPoint) throws Throwable {
+ MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
+ log.debug("refreshCache aspect, method:{}", methodSignature.getName());
+ Object[] args = joinPoint.getArgs();
+ Object param = args[0];
+ Long appId;
+ if (param instanceof Application) {
+ appId = ((Application) param).getId();
+ } else {
+ Method method = param.getClass().getDeclaredMethod("getAppId");
+ method.setAccessible(true);
+ appId = (Long) method.invoke(param, null);
}
-
+ return FlinkTrackingTask.refreshTracking(
+ appId,
+ () -> {
+ try {
+ return joinPoint.proceed();
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ }
+ return null;
+ });
+ }
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/bean/AlertConfigWithParams.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/bean/AlertConfigWithParams.java
index 965028e8f..a90736739 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/bean/AlertConfigWithParams.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/bean/AlertConfigWithParams.java
@@ -35,58 +35,67 @@ import java.io.Serializable;
@Slf4j
public class AlertConfigWithParams implements Serializable {
- @ApiModelProperty(name = "id", value = "id")
- private Long id;
+ @ApiModelProperty(name = "id", value = "id")
+ private Long id;
- @ApiModelProperty(name = "userId", value = "user id")
- private Long userId;
+ @ApiModelProperty(name = "userId", value = "user id")
+ private Long userId;
- @ApiModelProperty(name = "alertName", value = "alert name")
- private String alertName;
+ @ApiModelProperty(name = "alertName", value = "alert name")
+ private String alertName;
- @ApiModelProperty(name = "alertType", value = "alert type")
- private Integer alertType;
+ @ApiModelProperty(name = "alertType", value = "alert type")
+ private Integer alertType;
- @ApiModelProperty(name = "emailParams", value = "email alert params")
- private AlertEmailParams emailParams;
+ @ApiModelProperty(name = "emailParams", value = "email alert params")
+ private AlertEmailParams emailParams;
- @ApiModelProperty(name = "dingTalkParams", value = "ding-talk alert params")
- private AlertDingTalkParams dingTalkParams;
+ @ApiModelProperty(name = "dingTalkParams", value = "ding-talk alert params")
+ private AlertDingTalkParams dingTalkParams;
- @ApiModelProperty(name = "weComParams", value = "we-com alert params")
- private AlertWeComParams weComParams;
+ @ApiModelProperty(name = "weComParams", value = "we-com alert params")
+ private AlertWeComParams weComParams;
- @ApiModelProperty(name = "httpCallbackParams", value = "http callback alert params")
- private AlertHttpCallbackParams httpCallbackParams;
+ @ApiModelProperty(name = "httpCallbackParams", value = "http callback alert params")
+ private AlertHttpCallbackParams httpCallbackParams;
- @ApiModelProperty(name = "larkParams", value = "lark alert params")
- private AlertLarkParams larkParams;
+ @ApiModelProperty(name = "larkParams", value = "lark alert params")
+ private AlertLarkParams larkParams;
... 44623 lines suppressed ...