You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by he...@apache.org on 2022/07/05 07:28:07 UTC
[inlong] branch master updated: [INLONG-4870][Manager] Refactor util classes (#4873)
This is an automated email from the ASF dual-hosted git repository.
healchow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/master by this push:
new cd082ba98 [INLONG-4870][Manager] Refactor util classes (#4873)
cd082ba98 is described below
commit cd082ba98e9f8451a842569d27daaa51fa6a1fcc
Author: healchow <he...@gmail.com>
AuthorDate: Tue Jul 5 15:28:03 2022 +0800
[INLONG-4870][Manager] Refactor util classes (#4873)
---
.../manager/client/api/InlongGroupContext.java | 4 +-
.../manager/client/api/impl/InlongGroupImpl.java | 47 +++---
.../manager/client/api/impl/InlongStreamImpl.java | 22 +--
.../client/api/inner/InnerGroupContext.java | 18 +-
.../client/api/inner/InnerInlongManagerClient.java | 49 +++---
.../api/transform/MultiDependencyTransform.java | 8 +-
.../api/transform/SingleDependencyTransform.java | 8 +-
.../client/api/util/InlongGroupTransfer.java | 17 +-
.../api/inner/InnerInlongManagerClientTest.java | 3 +-
.../manager/common/auth/DefaultAuthentication.java | 5 +-
.../manager/common/auth/SecretAuthentication.java | 4 +-
.../manager/common/auth/TokenAuthentication.java | 4 +-
.../common/pojo/group/InlongGroupRequest.java | 28 ----
.../inlong/manager/common/util/AssertUtils.java | 183 ---------------------
.../inlong/manager/common/util/DateUtils.java | 65 ++++++++
.../inlong/manager/common/util/HttpUtils.java | 62 ++++---
.../inlong/manager/common/util/MD5Utils.java | 78 +++++++++
.../inlong/manager/common/util/NetworkUtils.java | 39 ++++-
.../inlong/manager/common/util/Preconditions.java | 10 ++
.../inlong/manager/common/util/SmallTools.java | 142 ----------------
.../{SmallToolsTest.java => MD5UtilsTest.java} | 8 +-
.../manager/service/core/impl/UserServiceImpl.java | 19 +--
.../service/group/InlongGroupServiceImpl.java | 2 -
.../manager/service/mq/util/TubeMQOperator.java | 23 +--
.../web/controller/InlongGroupController.java | 7 +-
25 files changed, 334 insertions(+), 521 deletions(-)
diff --git a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/InlongGroupContext.java b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/InlongGroupContext.java
index 1925e74a0..22d89d155 100644
--- a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/InlongGroupContext.java
+++ b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/InlongGroupContext.java
@@ -29,8 +29,8 @@ import org.apache.inlong.manager.client.api.inner.InnerGroupContext;
import org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo;
import org.apache.inlong.manager.common.pojo.group.InlongGroupInfo;
import org.apache.inlong.manager.common.pojo.source.StreamSource;
-import org.apache.inlong.manager.common.util.AssertUtils;
import org.apache.inlong.manager.common.util.JsonUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
import java.io.Serializable;
import java.util.List;
@@ -75,7 +75,7 @@ public class InlongGroupContext implements Serializable {
public InlongGroupContext(InnerGroupContext groupContext) {
InlongGroupInfo groupInfo = groupContext.getGroupInfo();
- AssertUtils.notNull(groupInfo);
+ Preconditions.checkNotNull(groupInfo, "inlong group info cannot be null");
this.groupId = groupInfo.getInlongGroupId();
this.groupName = groupInfo.getName();
this.groupInfo = groupInfo;
diff --git a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/impl/InlongGroupImpl.java b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/impl/InlongGroupImpl.java
index 2b2e5b33f..bdeb65236 100644
--- a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/impl/InlongGroupImpl.java
+++ b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/impl/InlongGroupImpl.java
@@ -43,8 +43,8 @@ import org.apache.inlong.manager.common.pojo.workflow.ProcessResponse;
import org.apache.inlong.manager.common.pojo.workflow.TaskResponse;
import org.apache.inlong.manager.common.pojo.workflow.WorkflowResult;
import org.apache.inlong.manager.common.pojo.workflow.form.process.NewGroupProcessForm;
-import org.apache.inlong.manager.common.util.AssertUtils;
import org.apache.inlong.manager.common.util.JsonUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
import org.springframework.boot.configurationprocessor.json.JSONObject;
import java.util.List;
@@ -77,7 +77,7 @@ public class InlongGroupImpl implements InlongGroup {
this.groupContext.setGroupInfo(groupInfo);
} else {
BaseSortConf sortConf = groupInfo.getSortConf();
- groupInfo = InlongGroupTransfer.createGroupInfo(groupInfo, sortConf);
+ InlongGroupTransfer.createGroupInfo(groupInfo, sortConf);
String groupId = managerClient.createGroup(groupInfo.genRequest());
groupInfo.setInlongGroupId(groupId);
}
@@ -98,19 +98,19 @@ public class InlongGroupImpl implements InlongGroup {
InlongGroupInfo groupInfo = this.groupContext.getGroupInfo();
WorkflowResult initWorkflowResult = managerClient.initInlongGroup(groupInfo.genRequest());
List<TaskResponse> taskViews = initWorkflowResult.getNewTasks();
- AssertUtils.notEmpty(taskViews, "Init business info failed");
+ Preconditions.checkNotEmpty(taskViews, "init inlong group info failed");
TaskResponse taskView = taskViews.get(0);
final int taskId = taskView.getId();
ProcessResponse processView = initWorkflowResult.getProcessInfo();
- AssertUtils.isTrue(ProcessStatus.PROCESSING == processView.getStatus(),
- String.format("Process status : %s is not corrected, should be PROCESSING",
- processView.getStatus()));
+ Preconditions.checkTrue(ProcessStatus.PROCESSING == processView.getStatus(),
+ String.format("process status %s is not corrected, should be PROCESSING", processView.getStatus()));
// init must be NewGroupProcessForm
// compile with old cluster
- JSONObject formDataJson =
- JsonUtils.parseObject(JsonUtils.toJsonString(JsonUtils.toJsonString(processView.getFormData())),
- JSONObject.class);
+ JSONObject formDataJson = JsonUtils.parseObject(
+ JsonUtils.toJsonString(JsonUtils.toJsonString(processView.getFormData())),
+ JSONObject.class);
+ assert formDataJson != null;
if (formDataJson.has(GROUP_FIELD)) {
JSONObject groupInfoJson = formDataJson.getJSONObject(GROUP_FIELD);
if (groupInfoJson.has(MQ_FIELD_OLD) && !groupInfoJson.has(MQ_FIELD)) {
@@ -120,13 +120,12 @@ public class InlongGroupImpl implements InlongGroup {
String formDataNew = formDataJson.toString();
NewGroupProcessForm newGroupProcessForm = JsonUtils.parseObject(
formDataNew, NewGroupProcessForm.class);
- AssertUtils.notNull(newGroupProcessForm, "NewGroupProcessForm cannot be null");
-
+ Preconditions.checkNotNull(newGroupProcessForm, "NewGroupProcessForm cannot be null");
groupContext.setInitMsg(newGroupProcessForm);
WorkflowResult startWorkflowResult = managerClient.startInlongGroup(taskId, newGroupProcessForm);
processView = startWorkflowResult.getProcessInfo();
- AssertUtils.isTrue(ProcessStatus.COMPLETED == processView.getStatus(),
- String.format("inlong group status %s is incorrected, should be COMPLETED", processView.getStatus()));
+ Preconditions.checkTrue(ProcessStatus.COMPLETED == processView.getStatus(),
+ String.format("inlong group status %s is incorrect, should be COMPLETED", processView.getStatus()));
return generateSnapshot();
}
@@ -137,19 +136,19 @@ public class InlongGroupImpl implements InlongGroup {
}
final String groupId = originGroupInfo.getInlongGroupId();
- AssertUtils.isTrue(groupId != null && groupId.equals(this.groupInfo.getInlongGroupId()),
+ Preconditions.checkTrue(groupId != null && groupId.equals(this.groupInfo.getInlongGroupId()),
"groupId must be same");
InlongGroupInfo existGroupInfo = managerClient.getGroupInfo(groupId);
SimpleGroupStatus status = SimpleGroupStatus.parseStatusByCode(existGroupInfo.getStatus());
- AssertUtils.isTrue(status != SimpleGroupStatus.INITIALIZING,
- "Inlong Group is in init status, should not be updated");
+ Preconditions.checkTrue(status != SimpleGroupStatus.INITIALIZING,
+ "inlong group is in init status, should not be updated");
InlongGroupInfo groupInfo = InlongGroupTransfer.createGroupInfo(originGroupInfo, sortConf);
InlongGroupRequest groupRequest = groupInfo.genRequest();
Pair<String, String> idAndErr = managerClient.updateGroup(groupRequest);
String errMsg = idAndErr.getValue();
- AssertUtils.isNull(errMsg, errMsg);
+ Preconditions.checkNull(errMsg, errMsg);
this.groupContext.setGroupInfo(groupInfo);
this.groupInfo = groupInfo;
@@ -157,28 +156,26 @@ public class InlongGroupImpl implements InlongGroup {
@Override
public void update(BaseSortConf sortConf) throws Exception {
- AssertUtils.notNull(sortConf, "SortConf should not be empty");
+ Preconditions.checkNotNull(sortConf, "sort conf cannot be null");
final String groupId = this.groupInfo.getInlongGroupId();
InlongGroupInfo groupInfo = managerClient.getGroupInfo(groupId);
SimpleGroupStatus status = SimpleGroupStatus.parseStatusByCode(groupInfo.getStatus());
- AssertUtils.isTrue(status != SimpleGroupStatus.INITIALIZING,
- "Inlong Group is in init status, should not be updated");
+ Preconditions.checkTrue(status != SimpleGroupStatus.INITIALIZING,
+ "inlong group is in init status, should not be updated");
groupInfo = InlongGroupTransfer.createGroupInfo(this.groupInfo, sortConf);
-
InlongGroupRequest groupRequest = groupInfo.genRequest();
Pair<String, String> idAndErr = managerClient.updateGroup(groupRequest);
String errMsg = idAndErr.getValue();
- AssertUtils.isNull(errMsg, errMsg);
+ Preconditions.checkNull(errMsg, errMsg);
this.groupContext.setGroupInfo(groupInfo);
}
@Override
public InlongGroupContext reInitOnUpdate(InlongGroupInfo originGroupInfo, BaseSortConf sortConf) throws Exception {
this.update(originGroupInfo, sortConf);
-
String inlongGroupId = this.groupContext.getGroupInfo().getInlongGroupId();
InlongGroupInfo newGroupInfo = managerClient.getGroupIfExists(inlongGroupId);
if (newGroupInfo != null) {
@@ -201,7 +198,7 @@ public class InlongGroupImpl implements InlongGroup {
Pair<String, String> idAndErr = managerClient.updateGroup(groupInfo.genRequest());
final String errMsg = idAndErr.getValue();
final String groupId = idAndErr.getKey();
- AssertUtils.isNull(errMsg, errMsg);
+ Preconditions.checkNull(errMsg, errMsg);
managerClient.operateInlongGroup(groupId, SimpleGroupStatus.STOPPED, async);
return generateSnapshot();
}
@@ -217,7 +214,7 @@ public class InlongGroupImpl implements InlongGroup {
Pair<String, String> idAndErr = managerClient.updateGroup(groupInfo.genRequest());
final String errMsg = idAndErr.getValue();
final String groupId = idAndErr.getKey();
- AssertUtils.isNull(errMsg, errMsg);
+ Preconditions.checkNull(errMsg, errMsg);
managerClient.operateInlongGroup(groupId, SimpleGroupStatus.STARTED, async);
return generateSnapshot();
}
diff --git a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/impl/InlongStreamImpl.java b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/impl/InlongStreamImpl.java
index c343be7e1..888127387 100644
--- a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/impl/InlongStreamImpl.java
+++ b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/impl/InlongStreamImpl.java
@@ -38,8 +38,8 @@ import org.apache.inlong.manager.common.pojo.stream.StreamPipeline;
import org.apache.inlong.manager.common.pojo.stream.StreamTransform;
import org.apache.inlong.manager.common.pojo.transform.TransformRequest;
import org.apache.inlong.manager.common.pojo.transform.TransformResponse;
-import org.apache.inlong.manager.common.util.AssertUtils;
import org.apache.inlong.manager.common.util.JsonUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
import java.util.List;
import java.util.Map;
@@ -138,10 +138,10 @@ public class InlongStreamImpl implements InlongStream {
@Override
public InlongStream addSource(StreamSource source) {
- AssertUtils.notNull(source.getSourceName(), "Source name should not be empty");
+ Preconditions.checkNotNull(source.getSourceName(), "source name cannot be null");
String sourceName = source.getSourceName();
if (streamSources.get(sourceName) != null) {
- throw new IllegalArgumentException(String.format("StreamSource=%s has already be set", source));
+ throw new IllegalArgumentException(String.format("source name=%s has already be set", source));
}
streamSources.put(sourceName, source);
return this;
@@ -149,10 +149,10 @@ public class InlongStreamImpl implements InlongStream {
@Override
public InlongStream addSink(StreamSink streamSink) {
- AssertUtils.notNull(streamSink.getSinkName(), "Sink name should not be empty");
+ Preconditions.checkNotNull(streamSink.getSinkName(), "sink name cannot be null");
String sinkName = streamSink.getSinkName();
if (streamSinks.get(sinkName) != null) {
- throw new IllegalArgumentException(String.format("StreamSink=%s has already be set", streamSink));
+ throw new IllegalArgumentException(String.format("sink name=%s has already be set", streamSink));
}
streamSinks.put(sinkName, streamSink);
return this;
@@ -160,10 +160,10 @@ public class InlongStreamImpl implements InlongStream {
@Override
public InlongStream addTransform(StreamTransform transform) {
- AssertUtils.notNull(transform.getTransformName(), "Transform name should not be empty");
+ Preconditions.checkNotNull(transform.getTransformName(), "transform name should not be empty");
String transformName = transform.getTransformName();
if (streamTransforms.get(transformName) != null) {
- throw new IllegalArgumentException(String.format("TransformName=%s has already be set", transform));
+ throw new IllegalArgumentException(String.format("transform name=%s has already be set", transform));
}
streamTransforms.put(transformName, transform);
return this;
@@ -189,21 +189,21 @@ public class InlongStreamImpl implements InlongStream {
@Override
public InlongStream updateSource(StreamSource source) {
- AssertUtils.notNull(source.getSourceName(), "Source name should not be empty");
+ Preconditions.checkNotNull(source.getSourceName(), "source name cannot be null");
streamSources.put(source.getSourceName(), source);
return this;
}
@Override
public InlongStream updateSink(StreamSink streamSink) {
- AssertUtils.notNull(streamSink.getSinkName(), "Sink name should not be empty");
+ Preconditions.checkNotNull(streamSink.getSinkName(), "sink name cannot be null");
streamSinks.put(streamSink.getSinkName(), streamSink);
return this;
}
@Override
public InlongStream updateTransform(StreamTransform transform) {
- AssertUtils.notNull(transform.getTransformName(), "Transform name should not be empty");
+ Preconditions.checkNotNull(transform.getTransformName(), "transform name cannot be null");
streamTransforms.put(transform.getTransformName(), transform);
return this;
}
@@ -285,7 +285,7 @@ public class InlongStreamImpl implements InlongStream {
InlongStreamInfo streamInfo = managerClient.getStreamInfo(inlongGroupId, inlongStreamId);
if (streamInfo == null) {
throw new IllegalArgumentException(
- String.format("Stream is not exists for group=%s and stream=%s", inlongGroupId, inlongStreamId));
+ String.format("Stream not exists for group=%s and stream=%s", inlongGroupId, inlongStreamId));
}
streamInfo.setFieldList(this.streamFields);
diff --git a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/InnerGroupContext.java b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/InnerGroupContext.java
index 5a7659d12..c67260883 100644
--- a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/InnerGroupContext.java
+++ b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/InnerGroupContext.java
@@ -21,11 +21,10 @@ import com.google.common.collect.Maps;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.StringUtils;
import org.apache.inlong.manager.client.api.InlongStream;
import org.apache.inlong.manager.common.pojo.group.InlongGroupInfo;
import org.apache.inlong.manager.common.pojo.workflow.form.process.NewGroupProcessForm;
-import org.apache.inlong.manager.common.util.AssertUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
import java.util.Map;
@@ -45,13 +44,13 @@ public class InnerGroupContext {
private NewGroupProcessForm initMsg;
public String getGroupId() {
- AssertUtils.notNull(groupInfo, "InlongGroupRequest is not init");
+ Preconditions.checkNotNull(groupInfo, "inlong group info was not init");
return groupInfo.getInlongGroupId();
}
public void setStreamContext(InnerStreamContext streamContext) {
- AssertUtils.isTrue(streamContext != null && streamContext.getStreamInfo() != null,
- "StreamContext should not be null");
+ Preconditions.checkTrue(streamContext != null && streamContext.getStreamInfo() != null,
+ "stream context cannot be null");
if (MapUtils.isEmpty(streamContextMap)) {
streamContextMap = Maps.newHashMap();
}
@@ -59,18 +58,11 @@ public class InnerGroupContext {
}
public void setStream(InlongStream stream) {
- AssertUtils.isTrue(stream != null, "Stream should not be null");
+ Preconditions.checkTrue(stream != null, "stream cannot be null");
if (MapUtils.isEmpty(streamMap)) {
streamMap = Maps.newHashMap();
}
streamMap.put(stream.getInlongStreamId(), stream);
}
- public InlongStream getStream(String streamId) {
- AssertUtils.isTrue(StringUtils.isNotEmpty(streamId), "Stream streamId should not be null");
- if (MapUtils.isNotEmpty(streamMap)) {
- return streamMap.get(streamId);
- }
- return null;
- }
}
diff --git a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/InnerInlongManagerClient.java b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/InnerInlongManagerClient.java
index 2895df7a3..32f3a1008 100644
--- a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/InnerInlongManagerClient.java
+++ b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/InnerInlongManagerClient.java
@@ -21,7 +21,6 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.pagehelper.PageInfo;
-import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
@@ -59,8 +58,8 @@ import org.apache.inlong.manager.common.pojo.transform.TransformResponse;
import org.apache.inlong.manager.common.pojo.workflow.EventLogView;
import org.apache.inlong.manager.common.pojo.workflow.WorkflowResult;
import org.apache.inlong.manager.common.pojo.workflow.form.process.NewGroupProcessForm;
-import org.apache.inlong.manager.common.util.AssertUtils;
import org.apache.inlong.manager.common.util.JsonUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
import org.springframework.boot.configurationprocessor.json.JSONObject;
import retrofit2.Call;
import retrofit2.Retrofit;
@@ -79,6 +78,8 @@ import static org.apache.inlong.manager.client.api.impl.InlongGroupImpl.MQ_FIELD
@Slf4j
public class InnerInlongManagerClient {
+ private static final String REQUEST_FAILED_MSG = "Request to Inlong %s failed: %s";
+
protected final String host;
protected final int port;
@@ -97,9 +98,9 @@ public class InnerInlongManagerClient {
this.port = configuration.getBindPort();
Authentication authentication = configuration.getAuthentication();
- AssertUtils.notNull(authentication, "Inlong should be authenticated");
- AssertUtils.isTrue(authentication instanceof DefaultAuthentication,
- "Inlong only support default authentication");
+ Preconditions.checkNotNull(authentication, "inlong should be authenticated");
+ Preconditions.checkTrue(authentication instanceof DefaultAuthentication,
+ "inlong only support default authentication");
DefaultAuthentication defaultAuthentication = (DefaultAuthentication) authentication;
OkHttpClient okHttpClient = new OkHttpClient.Builder()
@@ -133,9 +134,9 @@ public class InnerInlongManagerClient {
* @return clusterIndex
*/
public Integer saveCluster(ClusterRequest request) {
- AssertUtils.notEmpty(request.getName(), "cluster name should not be empty");
- AssertUtils.notEmpty(request.getType(), "cluster type should not be empty");
- AssertUtils.notEmpty(request.getClusterTags(), "cluster tags should not be empty");
+ Preconditions.checkNotEmpty(request.getName(), "cluster name should not be empty");
+ Preconditions.checkNotEmpty(request.getType(), "cluster type should not be empty");
+ Preconditions.checkNotEmpty(request.getClusterTags(), "cluster tags should not be empty");
Response<Integer> clusterIndexResponse = executeHttpCall(inlongClusterApi.save(request));
assertRespSuccess(clusterIndexResponse);
return clusterIndexResponse.getData();
@@ -158,7 +159,7 @@ public class InnerInlongManagerClient {
* Check whether a group exists based on the group ID.
*/
public Boolean isGroupExists(String inlongGroupId) {
- AssertUtils.notEmpty(inlongGroupId, "InlongGroupId should not be empty");
+ Preconditions.checkNotEmpty(inlongGroupId, "InlongGroupId should not be empty");
Response<Boolean> response = executeHttpCall(inlongGroupApi.isGroupExists(inlongGroupId));
assertRespSuccess(response);
@@ -170,7 +171,7 @@ public class InnerInlongManagerClient {
*/
@SneakyThrows
public InlongGroupInfo getGroupInfo(String inlongGroupId) {
- AssertUtils.notEmpty(inlongGroupId, "InlongGroupId should not be empty");
+ Preconditions.checkNotEmpty(inlongGroupId, "InlongGroupId should not be empty");
Response<Object> responseBody = executeHttpCall(inlongGroupApi.getGroupInfo(inlongGroupId));
if (responseBody.isSuccess()) {
@@ -180,9 +181,7 @@ public class InnerInlongManagerClient {
if (groupInfoJson.has(MQ_FIELD_OLD) && !groupInfoJson.has(MQ_FIELD)) {
groupInfoJson.put(MQ_FIELD, groupInfoJson.get(MQ_FIELD_OLD));
}
- InlongGroupInfo inlongGroupInfo = JsonUtils.parseObject(
- groupInfoJson.toString(), InlongGroupInfo.class);
- return inlongGroupInfo;
+ return JsonUtils.parseObject(groupInfoJson.toString(), InlongGroupInfo.class);
}
if (responseBody.getErrMsg().contains("not exist")) {
@@ -269,8 +268,8 @@ public class InnerInlongManagerClient {
public Boolean isStreamExists(InlongStreamInfo streamInfo) {
final String groupId = streamInfo.getInlongGroupId();
final String streamId = streamInfo.getInlongStreamId();
- AssertUtils.notEmpty(groupId, "InlongGroupId should not be empty");
- AssertUtils.notEmpty(streamId, "InlongStreamId should not be empty");
+ Preconditions.checkNotEmpty(groupId, "InlongGroupId should not be empty");
+ Preconditions.checkNotEmpty(streamId, "InlongStreamId should not be empty");
Response<Boolean> response = executeHttpCall(inlongStreamApi.isStreamExists(groupId, streamId));
assertRespSuccess(response);
@@ -357,7 +356,7 @@ public class InnerInlongManagerClient {
* Delete data source information by id.
*/
public boolean deleteSource(int id) {
- AssertUtils.isTrue(id > 0, "sourceId is illegal");
+ Preconditions.checkTrue(id > 0, "sourceId is illegal");
Response<Boolean> response = executeHttpCall(streamSourceApi.deleteSource(id));
assertRespSuccess(response);
return response.getData();
@@ -399,9 +398,9 @@ public class InnerInlongManagerClient {
* Delete conversion function information.
*/
public boolean deleteTransform(TransformRequest transformRequest) {
- AssertUtils.notEmpty(transformRequest.getInlongGroupId(), "inlongGroupId should not be null");
- AssertUtils.notEmpty(transformRequest.getInlongStreamId(), "inlongStreamId should not be null");
- AssertUtils.notEmpty(transformRequest.getTransformName(), "transformName should not be null");
+ Preconditions.checkNotEmpty(transformRequest.getInlongGroupId(), "inlongGroupId should not be null");
+ Preconditions.checkNotEmpty(transformRequest.getInlongStreamId(), "inlongStreamId should not be null");
+ Preconditions.checkNotEmpty(transformRequest.getTransformName(), "transformName should not be null");
Response<Boolean> response = executeHttpCall(
streamTransformApi.deleteTransform(transformRequest.getInlongGroupId(),
@@ -420,7 +419,7 @@ public class InnerInlongManagerClient {
* Delete information of data sink by ID.
*/
public boolean deleteSink(int id) {
- AssertUtils.isTrue(id > 0, "sinkId is illegal");
+ Preconditions.checkTrue(id > 0, "sinkId is illegal");
Response<Boolean> response = executeHttpCall(streamSinkApi.deleteSink(id));
assertRespSuccess(response);
return response.getData();
@@ -556,17 +555,17 @@ public class InnerInlongManagerClient {
String url = request.url().encodedPath();
try {
retrofit2.Response<T> response = call.execute();
- Preconditions.checkState(response.isSuccessful(),
- "Request to Inlong %s failed: %s", url, response.message());
+ Preconditions.checkTrue(response.isSuccessful(),
+ String.format(REQUEST_FAILED_MSG, url, response.message()));
return response.body();
} catch (IOException e) {
- log.error(String.format("Request to Inlong %s failed: %s", url, e.getMessage()), e);
- throw new RuntimeException(String.format("Request to Inlong %s failed: %s", url, e.getMessage()), e);
+ log.error(String.format(REQUEST_FAILED_MSG, url, e.getMessage()), e);
+ throw new RuntimeException(String.format(REQUEST_FAILED_MSG, url, e.getMessage()), e);
}
}
private void assertRespSuccess(Response<?> response) {
- Preconditions.checkState(response.isSuccess(), "Inlong request failed: %s", response.getErrMsg());
+ Preconditions.checkTrue(response.isSuccess(), String.format(REQUEST_FAILED_MSG, response.getErrMsg(), null));
}
}
diff --git a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/transform/MultiDependencyTransform.java b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/transform/MultiDependencyTransform.java
index 70915a821..7d0a5ec4f 100644
--- a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/transform/MultiDependencyTransform.java
+++ b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/transform/MultiDependencyTransform.java
@@ -20,7 +20,7 @@ package org.apache.inlong.manager.client.api.transform;
import io.swagger.annotations.ApiModel;
import org.apache.inlong.manager.common.pojo.stream.StreamTransform;
import org.apache.inlong.manager.common.pojo.transform.TransformDefinition;
-import org.apache.inlong.manager.common.util.AssertUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
import java.util.List;
@@ -39,11 +39,11 @@ public class MultiDependencyTransform extends StreamTransform {
* if pre streamNode is streamTransform, preNode is transformName
*/
public MultiDependencyTransform(String transformName, TransformDefinition transformDefinition, String... preNodes) {
- AssertUtils.notNull(transformDefinition, "TransformDefinition should not be null");
+ Preconditions.checkNotNull(transformDefinition, "transform definition cannot be null");
this.transformDefinition = transformDefinition;
- AssertUtils.notNull(transformName, "TransformName should not be empty");
+ Preconditions.checkNotNull(transformName, "transform name cannot be empty");
this.transformName = transformName;
- AssertUtils.noNullElements(preNodes, "Pre streamNode should not be null");
+ Preconditions.checkNotNullElements(preNodes, "pre nodes cannot be null");
for (String preNode : preNodes) {
this.addPre(preNode);
}
diff --git a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/transform/SingleDependencyTransform.java b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/transform/SingleDependencyTransform.java
index 322a62a56..6e767b057 100644
--- a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/transform/SingleDependencyTransform.java
+++ b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/transform/SingleDependencyTransform.java
@@ -20,7 +20,7 @@ package org.apache.inlong.manager.client.api.transform;
import io.swagger.annotations.ApiModel;
import org.apache.inlong.manager.common.pojo.stream.StreamTransform;
import org.apache.inlong.manager.common.pojo.transform.TransformDefinition;
-import org.apache.inlong.manager.common.util.AssertUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
/**
* StreamTransform with one pre stream node, such as filter, splitter, etc.
@@ -37,11 +37,11 @@ public class SingleDependencyTransform extends StreamTransform {
* if pre streamNode is streamTransform, preNode is transformName
*/
public SingleDependencyTransform(String transformName, TransformDefinition transformDefinition, String preNode) {
- AssertUtils.notNull(transformDefinition, "TransformDefinition should not be null");
+ Preconditions.checkNotNull(transformDefinition, "transform definition cannot be null");
this.transformDefinition = transformDefinition;
- AssertUtils.notNull(transformName, "TransformName should not be empty");
+ Preconditions.checkNotNull(transformName, "transform name cannot be null");
this.transformName = transformName;
- AssertUtils.notNull(preNode, "Pre streamNode should not be null");
+ Preconditions.checkNotNull(preNode, "pre nodes cannot be null");
this.addPre(preNode);
}
diff --git a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/util/InlongGroupTransfer.java b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/util/InlongGroupTransfer.java
index 0a247d259..2a03108d1 100644
--- a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/util/InlongGroupTransfer.java
+++ b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/util/InlongGroupTransfer.java
@@ -32,7 +32,7 @@ import org.apache.inlong.manager.common.pojo.sort.BaseSortConf;
import org.apache.inlong.manager.common.pojo.sort.BaseSortConf.SortType;
import org.apache.inlong.manager.common.pojo.sort.FlinkSortConf;
import org.apache.inlong.manager.common.pojo.sort.UserDefinedSortConf;
-import org.apache.inlong.manager.common.util.AssertUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
import java.util.ArrayList;
import java.util.List;
@@ -48,16 +48,17 @@ public class InlongGroupTransfer {
* Create inlong group info from group config.
*/
public static InlongGroupInfo createGroupInfo(InlongGroupInfo groupInfo, BaseSortConf sortConf) {
- AssertUtils.notNull(groupInfo, "Inlong group info cannot be null");
- AssertUtils.hasLength(groupInfo.getInlongGroupId(), "groupId cannot be empty");
+ Preconditions.checkNotNull(groupInfo, "Inlong group info cannot be null");
+ String groupId = groupInfo.getInlongGroupId();
+ Preconditions.checkNotEmpty(groupId, "groupId cannot be empty");
groupInfo.setExtList(Lists.newArrayList());
// set authentication into group ext list
List<InlongGroupExtInfo> extInfos = new ArrayList<>();
if (groupInfo.getAuthentication() != null) {
Authentication authentication = groupInfo.getAuthentication();
AuthType authType = authentication.getAuthType();
- AssertUtils.isTrue(authType == AuthType.TOKEN,
- String.format("Unsupported authentication:%s for pulsar", authType.name()));
+ Preconditions.checkTrue(authType == AuthType.TOKEN,
+ String.format("Unsupported authentication %s for Pulsar", authType.name()));
TokenAuthentication tokenAuthentication = (TokenAuthentication) authentication;
InlongGroupExtInfo authTypeExt = new InlongGroupExtInfo();
authTypeExt.setKeyName(InlongConstants.PULSAR_AUTHENTICATION_TYPE);
@@ -73,7 +74,7 @@ public class InlongGroupTransfer {
}
if (sortConf == null) {
- throw new IllegalArgumentException("sort config cannot be empty for group=" + groupInfo.getInlongGroupId());
+ throw new IllegalArgumentException("sort config cannot be empty for group=" + groupId);
}
// set the sort config into ext list
SortType sortType = sortConf.getType();
@@ -105,8 +106,8 @@ public class InlongGroupTransfer {
if (flinkSortConf.getAuthentication() != null) {
Authentication authentication = flinkSortConf.getAuthentication();
AuthType authType = authentication.getAuthType();
- AssertUtils.isTrue(authType == AuthType.SECRET_AND_TOKEN,
- String.format("Unsupported authentication:%s for flink", authType.name()));
+ Preconditions.checkTrue(authType == AuthType.SECRET_AND_TOKEN,
+ String.format("Unsupported authentication %s for Flink", authType.name()));
final SecretTokenAuthentication secretTokenAuthentication = (SecretTokenAuthentication) authentication;
InlongGroupExtInfo authTypeExt = new InlongGroupExtInfo();
authTypeExt.setKeyName(InlongConstants.SORT_AUTHENTICATION_TYPE);
diff --git a/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/inner/InnerInlongManagerClientTest.java b/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/inner/InnerInlongManagerClientTest.java
index 0abe199b4..2295c4eb8 100644
--- a/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/inner/InnerInlongManagerClientTest.java
+++ b/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/inner/InnerInlongManagerClientTest.java
@@ -646,9 +646,8 @@ class InnerInlongManagerClientTest {
)
);
- RuntimeException exception = Assertions.assertThrows(IllegalStateException.class,
+ RuntimeException exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> innerInlongManagerClient.listSinks("", "11"));
-
Assertions.assertTrue(exception.getMessage().contains("groupId should not empty"));
}
diff --git a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/auth/DefaultAuthentication.java b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/auth/DefaultAuthentication.java
index 3218040b3..4661356a9 100644
--- a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/auth/DefaultAuthentication.java
+++ b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/auth/DefaultAuthentication.java
@@ -20,7 +20,7 @@ package org.apache.inlong.manager.common.auth;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Getter;
import lombok.NoArgsConstructor;
-import org.apache.inlong.manager.common.util.AssertUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
import java.util.Map;
@@ -31,7 +31,6 @@ import java.util.Map;
public class DefaultAuthentication implements Authentication {
public static final String USERNAME = "username";
-
public static final String PASSWORD = "password";
@Getter
@@ -52,7 +51,7 @@ public class DefaultAuthentication implements Authentication {
@Override
public void configure(Map<String, String> properties) {
- AssertUtils.notEmpty(properties, "Properties should not be empty when init DefaultAuthentication");
+ Preconditions.checkNotEmpty(properties, "Properties cannot be empty when init DefaultAuthentication");
this.username = properties.get(USERNAME);
this.password = properties.get(PASSWORD);
}
diff --git a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/auth/SecretAuthentication.java b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/auth/SecretAuthentication.java
index 1c37d05e3..46dde8f8f 100644
--- a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/auth/SecretAuthentication.java
+++ b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/auth/SecretAuthentication.java
@@ -20,7 +20,7 @@ package org.apache.inlong.manager.common.auth;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Getter;
import lombok.NoArgsConstructor;
-import org.apache.inlong.manager.common.util.AssertUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
import java.util.Map;
@@ -52,7 +52,7 @@ public class SecretAuthentication implements Authentication {
@Override
public void configure(Map<String, String> properties) {
- AssertUtils.notEmpty(properties, "Properties should not be empty when init SecretAuthentication");
+ Preconditions.checkNotEmpty(properties, "Properties cannot be empty when init SecretAuthentication");
this.secretId = properties.get(SECRET_ID);
this.secretKey = properties.get(SECRET_KEY);
}
diff --git a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/auth/TokenAuthentication.java b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/auth/TokenAuthentication.java
index 7857bf235..a5f23bb0f 100644
--- a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/auth/TokenAuthentication.java
+++ b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/auth/TokenAuthentication.java
@@ -20,7 +20,7 @@ package org.apache.inlong.manager.common.auth;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Getter;
import lombok.NoArgsConstructor;
-import org.apache.inlong.manager.common.util.AssertUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
import java.util.Map;
@@ -46,7 +46,7 @@ public class TokenAuthentication implements Authentication {
@Override
public void configure(Map<String, String> properties) {
- AssertUtils.notEmpty(properties, "Properties should not be empty when init TokenAuthentication");
+ Preconditions.checkNotEmpty(properties, "Properties cannot be empty when init TokenAuthentication");
this.token = properties.get(TOKEN);
}
diff --git a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/pojo/group/InlongGroupRequest.java b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/pojo/group/InlongGroupRequest.java
index 2742160d2..d809ed32f 100644
--- a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/pojo/group/InlongGroupRequest.java
+++ b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/pojo/group/InlongGroupRequest.java
@@ -25,9 +25,6 @@ import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.inlong.manager.common.exceptions.BusinessException;
-import org.apache.inlong.manager.common.util.SmallTools;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
@@ -113,29 +110,4 @@ public class InlongGroupRequest {
@ApiModelProperty(value = "Inlong group Extension properties")
private List<InlongGroupExtInfo> extList;
- /**
- * Check the validation of request params
- */
- public void checkParams() {
- if (StringUtils.isBlank(inlongGroupId)) {
- throw new BusinessException("inlongGroupId cannot be null");
- }
-
- if (inlongGroupId.length() < 4 || inlongGroupId.length() > 100) {
- throw new BusinessException("characters for inlongGroupId must be more than 4 and less than 100");
- }
-
- if (!SmallTools.isLowerOrNum(inlongGroupId)) {
- throw new BusinessException("inlongGroupId only supports lowercase letters, numbers, '-', or '_'");
- }
-
- if (StringUtils.isBlank(mqType)) {
- throw new BusinessException("mqType cannot be null");
- }
-
- if (StringUtils.isBlank(inCharges)) {
- throw new BusinessException("inCharges cannot be null");
- }
- }
-
}
diff --git a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/AssertUtils.java b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/AssertUtils.java
deleted file mode 100644
index 0e4558658..000000000
--- a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/AssertUtils.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.inlong.manager.common.util;
-
-import org.apache.commons.lang3.StringUtils;
-
-import java.util.Collection;
-import java.util.Map;
-
-public class AssertUtils {
-
- public static void isTrue(boolean expression, String message) {
- if (!expression) {
- throw new IllegalStateException(message);
- }
- }
-
- public static void isTrue(boolean expression) {
- isTrue(expression, "[Assertion failed] - this expression must be true");
- }
-
- public static void isNull(Object object, String message) {
- if (object != null) {
- throw new IllegalStateException(message);
- }
- }
-
- public static void isNull(Object object) {
- isNull(object, "[Assertion failed] - the object argument must be null");
- }
-
- public static void notNull(Object object, String message) {
- if (object == null) {
- throw new IllegalStateException(message);
- }
- }
-
- public static void notNull(Object object) {
- notNull(object, "[Assertion failed] - this argument is required; it must not be null");
- }
-
- public static void hasLength(String text, String message) {
- if (StringUtils.isEmpty(text)) {
- throw new IllegalStateException(message);
- }
- }
-
- public static void hasLength(String text) {
- hasLength(text, "[Assertion failed] - this String argument must have length; it must not be null or empty");
- }
-
- public static void hasText(String text, String message) {
- if (StringUtils.isEmpty(text)) {
- throw new IllegalStateException(message);
- }
- }
-
- public static void hasText(String text) {
- hasText(text, "[Assertion failed] - this String argument must have text; it must not be null, empty, or blank");
- }
-
- public static void doesNotContain(String textToSearch, String substring, String message) {
- if (StringUtils.isNotEmpty(textToSearch) && StringUtils.isNotEmpty(substring)
- && textToSearch.indexOf(substring) != -1) {
- throw new IllegalStateException(message);
- }
- }
-
- public static void doesNotContain(String textToSearch, String substring) {
- doesNotContain(textToSearch, substring,
- "[Assertion failed] - this String argument must not contain the substring [" + substring + "]");
- }
-
- public static void noNullElements(Object[] array, String message) {
- if (array != null) {
- for (int i = 0; i < array.length; ++i) {
- if (array[i] == null) {
- throw new IllegalStateException(message);
- }
- }
- }
-
- }
-
- public static void noNullElements(Object[] array) {
- noNullElements(array, "[Assertion failed] - this array must not contain any null elements");
- }
-
- public static void notEmpty(Object[] array, String message) {
- if (array == null || array.length == 0) {
- throw new IllegalStateException(message);
- }
- }
-
- public static void notEmpty(String obj, String message) {
- if (StringUtils.isEmpty(obj)) {
- throw new IllegalStateException(message);
- }
- }
-
- public static void notEmpty(Object[] array) {
- notEmpty(array, "[Assertion failed] - this array must not be empty: it must contain at least 1 element");
- }
-
- public static void notEmpty(Collection collection, String message) {
- if (isEmpty(collection)) {
- throw new IllegalStateException(message);
- }
- }
-
- public static void notEmpty(Collection collection) {
- notEmpty(collection,
- "[Assertion failed] - this collection must not be empty: it must contain at least 1 element");
- }
-
- public static void notEmpty(Map map, String message) {
- if (isEmpty(map)) {
- throw new IllegalStateException(message);
- }
- }
-
- public static void notEmpty(Map map) {
- notEmpty(map, "[Assertion failed] - this map must not be empty; it must contain at least one entry");
- }
-
- public static void isInstanceOf(Class clazz, Object obj) {
- isInstanceOf(clazz, obj, "");
- }
-
- public static void isInstanceOf(Class type, Object obj, String message) {
- notNull(type, "Type to check against must not be null");
- if (!type.isInstance(obj)) {
- throw new IllegalStateException(
- message + "Object of class [" + (obj != null ? obj.getClass().getName() : "null")
- + "] must be an instance of " + type);
- }
- }
-
- public static void isAssignable(Class superType, Class subType) {
- isAssignable(superType, subType, "");
- }
-
- public static void isAssignable(Class superType, Class subType, String message) {
- notNull(superType, "Type to check against must not be null");
- if (subType == null || !superType.isAssignableFrom(subType)) {
- throw new IllegalStateException(message + subType + " is not assignable to " + superType);
- }
- }
-
- public static void state(boolean expression, String message) {
- if (!expression) {
- throw new IllegalStateException(message);
- }
- }
-
- public static void state(boolean expression) {
- state(expression, "[Assertion failed] - this state invariant must be true");
- }
-
- private static boolean isEmpty(Map m) {
- return m == null || m.isEmpty();
- }
-
- private static boolean isEmpty(Collection c) {
- return c == null || c.isEmpty();
- }
-
-}
diff --git a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/DateUtils.java b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/DateUtils.java
new file mode 100644
index 000000000..ec4b4a742
--- /dev/null
+++ b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/DateUtils.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.common.util;
+
+import lombok.experimental.UtilityClass;
+import lombok.extern.slf4j.Slf4j;
+
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * Date utils.
+ */
+@Slf4j
+@UtilityClass
+public class DateUtils {
+
+ /**
+ * Get the expiration date from the current time.
+ *
+ * @param afterDays expires after days
+ * @return expiration date
+ */
+ public static Date getExpirationDate(Integer afterDays) {
+ Date date = new Date();
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(date);
+ cal.add(Calendar.DATE, afterDays);
+ return cal.getTime();
+ }
+
+ /**
+ * Get valid days from the beginning date to the end date.
+ *
+ * @param begin begin date
+ * @param end due date
+ * @return valid days
+ */
+ public static Integer getValidDays(Date begin, Date end) {
+ ZoneId zoneId = ZoneId.systemDefault();
+
+ LocalDate createLocalDate = begin.toInstant().atZone(zoneId).toLocalDate();
+ LocalDate dueLocalDate = end.toInstant().atZone(zoneId).toLocalDate();
+
+ return Math.toIntExact(dueLocalDate.toEpochDay() - createLocalDate.toEpochDay());
+ }
+
+}
diff --git a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/HttpUtils.java b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/HttpUtils.java
index d994c0596..13b6bbad8 100644
--- a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/HttpUtils.java
+++ b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/HttpUtils.java
@@ -19,37 +19,40 @@ package org.apache.inlong.manager.common.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
/**
* HTTP utils
*/
-@Component
@Slf4j
public class HttpUtils {
- private static final Gson gson = new GsonBuilder().create(); // thread safe
- @Autowired
- private RestTemplate restTemplate;
+ private static final Gson GSON = new GsonBuilder().create(); // thread safe
+ /**
+ * Check whether the host and port can connect
+ *
+ * @param host target host address
+ * @param port target port
+ * @param connectTimeout connect timeout
+ * @param timeUnit time unit of timeout
+ * @return true if connect successfully, false if connect failed
+ */
public static boolean checkConnectivity(String host, int port, int connectTimeout, TimeUnit timeUnit) {
InetSocketAddress socketAddress = new InetSocketAddress(host, port);
Socket socket = new Socket();
@@ -69,17 +72,15 @@ public class HttpUtils {
}
/**
- * Send an HTTP request
+ * Send an HTTP request by the given rest template.
*/
- public <T> T request(String url, HttpMethod method, String param, HttpHeaders header, Class<T> cls)
- throws Exception {
- // Set request header parameters
+ public static <T> T request(RestTemplate restTemplate, String url, HttpMethod method,
+ String param, HttpHeaders header, Class<T> cls) throws Exception {
ResponseEntity<String> exchange;
try {
HttpEntity<String> request = new HttpEntity<>(param, header);
- log.debug("send http request to {}, param {}", url, param);
+ log.debug("send request to {}, param {}", url, param);
exchange = restTemplate.exchange(url, method, request, String.class);
-
String body = exchange.getBody();
HttpStatus statusCode = exchange.getStatusCode();
if (!statusCode.is2xxSuccessful()) {
@@ -87,9 +88,9 @@ public class HttpUtils {
}
log.debug("response from {}, status code {}", url, statusCode);
- return gson.fromJson(exchange.getBody(), cls);
+ return GSON.fromJson(exchange.getBody(), cls);
} catch (RestClientException e) {
- log.error(" do request for {} exception {} ", url, e.getMessage());
+ log.error("request for {} exception {} ", url, e.getMessage());
throw e;
}
}
@@ -97,31 +98,28 @@ public class HttpUtils {
/**
* Send an HTTP request
*/
- public <T> T request(String url, HttpMethod httpMethod, Object requestBody, HttpHeaders header,
- ParameterizedTypeReference<T> typeReference) {
+ public <T> T request(RestTemplate restTemplate, String url, HttpMethod httpMethod, Object requestBody,
+ HttpHeaders header, ParameterizedTypeReference<T> typeReference) {
if (log.isDebugEnabled()) {
- log.debug("call {}, request body {}", url, gson.toJson(requestBody));
+ log.debug("begin request to {} by request body {}", url, GSON.toJson(requestBody));
}
HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, header);
ResponseEntity<T> response = restTemplate.exchange(url, httpMethod, requestEntity, typeReference);
- if (log.isDebugEnabled()) {
- log.debug("call {}, status code {}", url, response.getStatusCode());
- }
-
+ log.debug("success request to {}, status code {}", url, response.getStatusCode());
Preconditions.checkTrue(response.getStatusCode().is2xxSuccessful(), "Request failed");
return response.getBody();
}
- public <T> T postRequest(String url, Object params, HttpHeaders header,
+ public <T> T postRequest(RestTemplate restTemplate, String url, Object params, HttpHeaders header,
ParameterizedTypeReference<T> typeReference) {
- return request(url, HttpMethod.POST, params, header, typeReference);
+ return request(restTemplate, url, HttpMethod.POST, params, header, typeReference);
}
- public <T> T getRequest(String url, Map<String, Object> params, HttpHeaders header,
+ public <T> T getRequest(RestTemplate restTemplate, String url, Map<String, Object> params, HttpHeaders header,
ParameterizedTypeReference<T> typeReference) {
- return request(buildUrlWithQueryParam(url, params), HttpMethod.GET, null, header, typeReference);
+ return request(restTemplate, buildUrlWithQueryParam(url, params), HttpMethod.GET, null, header, typeReference);
}
private String buildUrlWithQueryParam(String url, Map<String, Object> params) {
diff --git a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/MD5Utils.java b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/MD5Utils.java
new file mode 100644
index 000000000..a57d94553
--- /dev/null
+++ b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/MD5Utils.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.common.util;
+
+import lombok.experimental.UtilityClass;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.crypto.hash.SimpleHash;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * MD5 encryption and decryption utils.
+ */
+@Slf4j
+@UtilityClass
+public class MD5Utils {
+
+ private static final char[] hexDigits = {'0', '1', '2', '3', '4', '5',
+ '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+
+ /**
+ * Get MD5 from the given string.
+ *
+ * @param source string to be encrypted
+ * @return MD5 string after encrypt
+ */
+ public static String getMD5String(String source) {
+ if (source == null) {
+ return null;
+ }
+
+ String retString = null;
+ try {
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ md.update(source.getBytes(), 0, source.length());
+ byte[] retBytes = md.digest();
+
+ StringBuilder sb = new StringBuilder();
+ for (byte b : retBytes) {
+ sb.append(hexDigits[(b >> 4) & 0x0f]);
+ sb.append(hexDigits[b & 0x0f]);
+ }
+
+ retString = sb.toString();
+ } catch (NoSuchAlgorithmException e) {
+ log.error("" + e);
+ }
+
+ return retString;
+ }
+
+ /**
+ * Encrypt the given string by MD5 encryption algorithm.
+ *
+ * @param source string to be encrypted
+ * @return MD5 string after encrypt
+ */
+ public static String encrypt(String source) {
+ return new SimpleHash("MD5", source, null, 1024).toHex();
+ }
+
+}
diff --git a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/NetworkUtils.java b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/NetworkUtils.java
index 173185559..b841ace93 100644
--- a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/NetworkUtils.java
+++ b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/NetworkUtils.java
@@ -17,17 +17,20 @@
package org.apache.inlong.manager.common.util;
+import lombok.experimental.UtilityClass;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+
+import javax.servlet.http.HttpServletRequest;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import javax.servlet.http.HttpServletRequest;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
/**
* Utils for Network
*/
@Slf4j
+@UtilityClass
public class NetworkUtils {
/**
@@ -69,9 +72,8 @@ public class NetworkUtils {
* @return local IP
*/
public static String getLocalIp() {
- InetAddress localHost = null;
try {
- localHost = Inet4Address.getLocalHost();
+ InetAddress localHost = Inet4Address.getLocalHost();
return localHost.getHostAddress();
} catch (UnknownHostException e) {
log.error(e.getMessage(), e);
@@ -79,4 +81,31 @@ public class NetworkUtils {
return null;
}
+ /**
+ * Check if the IP string is valid.
+ *
+ * @param text IP string need to check
+ * @return true: valid, false: invalid
+ */
+ public static boolean ipCheck(String text) {
+ if (text != null && !text.isEmpty()) {
+ String regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
+ + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
+ + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
+ + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
+ return text.matches(regex);
+ }
+ return false;
+ }
+
+ /**
+ * Check if the port is valid.
+ *
+ * @param port port need to check
+ * @return true: valid, false: invalid
+ */
+ public static boolean portCheck(int port) {
+ return port > 0 && port < 65535;
+ }
+
}
diff --git a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/Preconditions.java b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/Preconditions.java
index 4bbe861f6..805dbe581 100644
--- a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/Preconditions.java
+++ b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/Preconditions.java
@@ -90,6 +90,16 @@ public class Preconditions {
checkTrue(map != null && !map.isEmpty(), errMsg);
}
+ public static void checkNotNullElements(Object[] array, String errMsg) {
+ if (array != null) {
+ for (Object o : array) {
+ if (o == null) {
+ throw new IllegalArgumentException(errMsg);
+ }
+ }
+ }
+ }
+
public static void checkFalse(boolean condition, String errMsg) {
checkTrue(!condition, errMsg);
}
diff --git a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/SmallTools.java b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/SmallTools.java
deleted file mode 100644
index ab743449a..000000000
--- a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/SmallTools.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.inlong.manager.common.util;
-
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shiro.crypto.hash.SimpleHash;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.time.LocalDate;
-import java.time.ZoneId;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.regex.Pattern;
-
-/**
- * Common tools
- */
-@Slf4j
-public class SmallTools {
-
- private static final Pattern LOWER_NUMBER_PATTERN = Pattern.compile("^(?![0-9]+$)[a-z][a-z0-9_-]{1,200}$");
-
- private static final char[] hexDigits = {'0', '1', '2', '3', '4', '5',
- '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
-
- /**
- * Check if the string starts with a lowercase letter and contains only lowercase letters, digits, `-` or `_`.
- */
- public static boolean isLowerOrNum(String str) {
- if (StringUtils.isNotBlank(str)) {
- return LOWER_NUMBER_PATTERN.matcher(str).matches();
- }
- return false;
- }
-
- /**
- * IP validation check
- *
- * @param text need to check
- * @return true: valid, false: invalid
- */
- public static boolean ipCheck(String text) {
- if (text != null && !text.isEmpty()) {
- String regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
- + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
- + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
- + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
- return text.matches(regex);
- }
- return false;
- }
-
- public static boolean portCheck(int port) {
- return port > 0 && port < 65535;
- }
-
- /**
- * Get MD5 from the given string
- */
- public static String getMD5String(String source) {
- if (source == null) {
- return null;
- }
-
- String retString = null;
- try {
- MessageDigest md = MessageDigest.getInstance("MD5");
- md.update(source.getBytes(), 0, source.length());
- byte[] retBytes = md.digest();
-
- StringBuilder sb = new StringBuilder();
- for (byte b : retBytes) {
- sb.append(hexDigits[(b >> 4) & 0x0f]);
- sb.append(hexDigits[b & 0x0f]);
- }
-
- retString = sb.toString();
- } catch (NoSuchAlgorithmException e) {
- log.error("" + e);
- }
-
- return retString;
- }
-
- /**
- * Encrypt user password by MD5 encryption algorithm
- *
- * @param password user password
- * @return password after encrypt
- */
- public static String passwordMd5(String password) {
- return new SimpleHash("MD5", password, null, 1024).toHex();
- }
-
- /**
- * Calculate expiration date
- *
- * @param validDays Expires in validDays
- * @return expiration date
- */
- public static Date getOverDueDate(Integer validDays) {
- Date date = new Date();
- Calendar cal = Calendar.getInstance();
- cal.setTime(date);
- cal.add(Calendar.DATE, validDays);
- return cal.getTime();
- }
-
- /**
- * Get valid days
- *
- * @param createDate create date
- * @param dueDate due date
- * @return valid days
- */
- public static Integer getValidDays(Date createDate, Date dueDate) {
- ZoneId zoneId = ZoneId.systemDefault();
-
- LocalDate createLocalDate = createDate.toInstant().atZone(zoneId).toLocalDate();
- LocalDate dueLocalDate = dueDate.toInstant().atZone(zoneId).toLocalDate();
-
- return Math.toIntExact(dueLocalDate.toEpochDay() - createLocalDate.toEpochDay());
- }
-
-}
diff --git a/inlong-manager/manager-common/src/test/java/org/apache/inlong/manager/common/util/SmallToolsTest.java b/inlong-manager/manager-common/src/test/java/org/apache/inlong/manager/common/util/MD5UtilsTest.java
similarity index 84%
rename from inlong-manager/manager-common/src/test/java/org/apache/inlong/manager/common/util/SmallToolsTest.java
rename to inlong-manager/manager-common/src/test/java/org/apache/inlong/manager/common/util/MD5UtilsTest.java
index b2be473c2..8d4c87caf 100644
--- a/inlong-manager/manager-common/src/test/java/org/apache/inlong/manager/common/util/SmallToolsTest.java
+++ b/inlong-manager/manager-common/src/test/java/org/apache/inlong/manager/common/util/MD5UtilsTest.java
@@ -20,11 +20,13 @@ package org.apache.inlong.manager.common.util;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-public class SmallToolsTest {
+public class MD5UtilsTest {
@Test
public void testIsLetterOrPattern() {
- String testGroupId = "test14DisableZkFor";
- Assertions.assertFalse(SmallTools.isLowerOrNum(testGroupId));
+ String str1 = "test_str";
+ String str2 = "test_str";
+ Assertions.assertEquals(MD5Utils.encrypt(str1), MD5Utils.encrypt(str2));
}
+
}
diff --git a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/UserServiceImpl.java b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/UserServiceImpl.java
index 46916d48b..99c78b779 100644
--- a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/UserServiceImpl.java
+++ b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/UserServiceImpl.java
@@ -30,10 +30,11 @@ import org.apache.inlong.manager.common.pojo.user.UserDetailPageRequest;
import org.apache.inlong.manager.common.pojo.user.UserInfo;
import org.apache.inlong.manager.common.util.AESUtils;
import org.apache.inlong.manager.common.util.CommonBeanUtils;
+import org.apache.inlong.manager.common.util.DateUtils;
import org.apache.inlong.manager.common.util.LoginUserUtils;
+import org.apache.inlong.manager.common.util.MD5Utils;
import org.apache.inlong.manager.common.util.Preconditions;
import org.apache.inlong.manager.common.util.RSAUtils;
-import org.apache.inlong.manager.common.util.SmallTools;
import org.apache.inlong.manager.dao.entity.UserEntity;
import org.apache.inlong.manager.dao.entity.UserEntityExample;
import org.apache.inlong.manager.dao.entity.UserEntityExample.Criteria;
@@ -47,8 +48,6 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
-import static org.apache.inlong.manager.common.util.SmallTools.getOverDueDate;
-
/**
* User service layer implementation
*/
@@ -76,7 +75,7 @@ public class UserServiceImpl implements UserService {
UserInfo result = new UserInfo();
result.setId(entity.getId());
result.setUsername(entity.getName());
- result.setValidDays(SmallTools.getValidDays(entity.getCreateTime(), entity.getDueDate()));
+ result.setValidDays(DateUtils.getValidDays(entity.getCreateTime(), entity.getDueDate()));
result.setType(entity.getAccountType());
try {
@@ -105,8 +104,8 @@ public class UserServiceImpl implements UserService {
UserEntity entity = new UserEntity();
entity.setAccountType(userInfo.getType());
- entity.setPassword(SmallTools.passwordMd5(userInfo.getPassword()));
- entity.setDueDate(getOverDueDate(userInfo.getValidDays()));
+ entity.setPassword(MD5Utils.encrypt(userInfo.getPassword()));
+ entity.setDueDate(DateUtils.getExpirationDate(userInfo.getValidDays()));
entity.setCreateBy(LoginUserUtils.getLoginUserDetail().getUsername());
entity.setName(username);
try {
@@ -145,8 +144,8 @@ public class UserServiceImpl implements UserService {
UserEntity entity = userMapper.selectByPrimaryKey(userInfo.getId());
Preconditions.checkNotNull(entity, "User not exists with id " + userInfo.getId());
- // update password by updatePassword()
- entity.setDueDate(getOverDueDate(userInfo.getValidDays()));
+ // update password
+ entity.setDueDate(DateUtils.getExpirationDate(userInfo.getValidDays()));
entity.setAccountType(userInfo.getType());
entity.setName(userInfo.getUsername());
@@ -161,9 +160,9 @@ public class UserServiceImpl implements UserService {
Preconditions.checkNotNull(entity, "User [" + username + "] not exists");
String oldPassword = request.getOldPassword();
- String oldPasswordMd = SmallTools.passwordMd5(oldPassword);
+ String oldPasswordMd = MD5Utils.encrypt(oldPassword);
Preconditions.checkTrue(oldPasswordMd.equals(entity.getPassword()), "Old password is wrong");
- String newPasswordMd5 = SmallTools.passwordMd5(request.getNewPassword());
+ String newPasswordMd5 = MD5Utils.encrypt(request.getNewPassword());
entity.setPassword(newPasswordMd5);
log.debug("success to update user password, username={}", username);
diff --git a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/group/InlongGroupServiceImpl.java b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/group/InlongGroupServiceImpl.java
index 8ddb55662..c785834ab 100644
--- a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/group/InlongGroupServiceImpl.java
+++ b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/group/InlongGroupServiceImpl.java
@@ -125,7 +125,6 @@ public class InlongGroupServiceImpl implements InlongGroupService {
public String save(InlongGroupRequest request, String operator) {
LOGGER.debug("begin to save inlong group={} by user={}", request, operator);
Preconditions.checkNotNull(request, "inlong group request cannot be empty");
- request.checkParams();
String groupId = request.getInlongGroupId();
InlongGroupEntity entity = groupMapper.selectByGroupId(groupId);
@@ -208,7 +207,6 @@ public class InlongGroupServiceImpl implements InlongGroupService {
public String update(InlongGroupRequest request, String operator) {
LOGGER.debug("begin to update inlong group={} by user={}", request, operator);
Preconditions.checkNotNull(request, "inlong group request cannot be empty");
- request.checkParams();
String groupId = request.getInlongGroupId();
InlongGroupEntity entity = groupMapper.selectByGroupId(groupId);
diff --git a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/mq/util/TubeMQOperator.java b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/mq/util/TubeMQOperator.java
index 1fa9e489a..92d4e3eae 100644
--- a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/mq/util/TubeMQOperator.java
+++ b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/mq/util/TubeMQOperator.java
@@ -33,6 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
import javax.annotation.Nonnull;
import java.util.List;
@@ -63,7 +64,7 @@ public class TubeMQOperator {
private static final String ADD_CONSUMER_PATH = "/webapi.htm?method=admin_add_authorized_consumergroup_info";
@Autowired
- private HttpUtils httpUtils;
+ private RestTemplate restTemplate;
/**
* Create topic for the given tube cluster.
@@ -117,8 +118,8 @@ public class TubeMQOperator {
LOGGER.info("begin to check if the tube topic {} exists", topicName);
String url = masterUrl + QUERY_TOPIC_PATH + TOPIC_NAME + topicName;
try {
- TopicResponse topicView = httpUtils.request(url, HttpMethod.GET, null, new HttpHeaders(),
- TopicResponse.class);
+ TopicResponse topicView = HttpUtils.request(restTemplate, url, HttpMethod.GET,
+ null, new HttpHeaders(), TopicResponse.class);
if (CollectionUtils.isEmpty(topicView.getData())) {
LOGGER.warn("tube topic {} not exists in {}", topicName, url);
return false;
@@ -139,8 +140,8 @@ public class TubeMQOperator {
LOGGER.info("begin to check if the consumer group {} exists on topic {}", consumerGroup, topicName);
String url = masterUrl + QUERY_CONSUMER_PATH + TOPIC_NAME + topicName + CONSUME_GROUP + consumerGroup;
try {
- ConsumerGroupResponse response = httpUtils.request(url, HttpMethod.GET, null, new HttpHeaders(),
- ConsumerGroupResponse.class);
+ ConsumerGroupResponse response = HttpUtils.request(restTemplate, url, HttpMethod.GET,
+ null, new HttpHeaders(), ConsumerGroupResponse.class);
if (CollectionUtils.isEmpty(response.getData())) {
LOGGER.warn("tube consumer group {} not exists for topic {} in {}", consumerGroup, topicName, url);
return false;
@@ -161,8 +162,8 @@ public class TubeMQOperator {
private TubeBrokerInfo getBrokerInfo(String masterUrl) {
String url = masterUrl + QUERY_BROKER_PATH;
try {
- TubeBrokerInfo brokerInfo = httpUtils.request(url, HttpMethod.GET, null, new HttpHeaders(),
- TubeBrokerInfo.class);
+ TubeBrokerInfo brokerInfo = HttpUtils.request(restTemplate, url, HttpMethod.GET,
+ null, new HttpHeaders(), TubeBrokerInfo.class);
if (brokerInfo.getErrCode() != SUCCESS_CODE) {
String msg = "failed to query tube broker from %s, error: %s";
LOGGER.error(String.format(msg, url, brokerInfo.getErrMsg()));
@@ -200,8 +201,8 @@ public class TubeMQOperator {
+ BROKER_ID + StringUtils.join(allBrokers, ",")
+ CREATE_USER + operator + CONF_MOD_AUTH_TOKEN + token;
try {
- TubeHttpResponse response = httpUtils.request(url, HttpMethod.GET, null, new HttpHeaders(),
- TubeHttpResponse.class);
+ TubeHttpResponse response = HttpUtils.request(restTemplate, url, HttpMethod.GET,
+ null, new HttpHeaders(), TubeHttpResponse.class);
if (response.getErrCode() != SUCCESS_CODE) {
String msg = String.format("failed to create tube topic %s, error: %s",
topicName, response.getErrMsg());
@@ -229,8 +230,8 @@ public class TubeMQOperator {
+ GROUP_NAME + consumerGroup
+ CREATE_USER + operator + CONF_MOD_AUTH_TOKEN + token;
try {
- TubeHttpResponse response = httpUtils.request(url, HttpMethod.GET, null, new HttpHeaders(),
- TubeHttpResponse.class);
+ TubeHttpResponse response = HttpUtils.request(restTemplate, url, HttpMethod.GET,
+ null, new HttpHeaders(), TubeHttpResponse.class);
if (response.getErrCode() != SUCCESS_CODE) {
String msg = String.format("failed to create tube consumer group %s for topic %s, error: %s",
consumerGroup, topicName, response.getErrMsg());
diff --git a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongGroupController.java b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongGroupController.java
index e7eacd030..6429b03ba 100644
--- a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongGroupController.java
+++ b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongGroupController.java
@@ -24,6 +24,7 @@ import io.swagger.annotations.ApiOperation;
import org.apache.inlong.manager.common.beans.Response;
import org.apache.inlong.manager.common.enums.OperationType;
import org.apache.inlong.manager.common.enums.UserTypeEnum;
+import org.apache.inlong.manager.common.pojo.common.UpdateValidation;
import org.apache.inlong.manager.common.pojo.group.InlongGroupCountResponse;
import org.apache.inlong.manager.common.pojo.group.InlongGroupInfo;
import org.apache.inlong.manager.common.pojo.group.InlongGroupListResponse;
@@ -61,8 +62,7 @@ public class InlongGroupController {
@RequestMapping(value = "/save", method = RequestMethod.POST)
@OperationLog(operation = OperationType.CREATE)
@ApiOperation(value = "Save inlong group info")
- public Response<String> save(@RequestBody InlongGroupRequest groupRequest) {
- groupRequest.checkParams();
+ public Response<String> save(@Validated @RequestBody InlongGroupRequest groupRequest) {
String operator = LoginUserUtils.getLoginUserDetail().getUsername();
return Response.success(groupService.save(groupRequest, operator));
}
@@ -85,8 +85,7 @@ public class InlongGroupController {
@RequestMapping(value = "/update", method = RequestMethod.POST)
@OperationLog(operation = OperationType.UPDATE)
@ApiOperation(value = "Update inlong group info")
- public Response<String> update(@RequestBody InlongGroupRequest groupRequest) {
- groupRequest.checkParams();
+ public Response<String> update(@Validated(UpdateValidation.class) @RequestBody InlongGroupRequest groupRequest) {
String operator = LoginUserUtils.getLoginUserDetail().getUsername();
return Response.success(groupService.update(groupRequest, operator));
}