fuweng11 commented on code in PR #8913:
URL: https://github.com/apache/inlong/pull/8913#discussion_r1327957468
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/tenant/InlongTenantServiceImpl.java:
##########
@@ -199,11 +221,122 @@ public Boolean delete(String name) {
throw new BusinessException(errMsg);
}
int success =
inlongTenantEntityMapper.deleteById(inlongTenantEntity.getId());
- Preconditions.expectTrue(success == 1, "delete failed");
+ Preconditions.expectTrue(success == InlongConstants.AFFECTED_ONE_ROW,
"delete failed");
log.info("success delete inlong tenant name={} by user={}", name,
operator);
return true;
}
+ @Override
+ public Boolean migrate(String groupId, String to) {
Review Comment:
migrate(String groupId, String targetTenant)
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/tenant/InlongTenantServiceImpl.java:
##########
@@ -199,11 +221,122 @@ public Boolean delete(String name) {
throw new BusinessException(errMsg);
}
int success =
inlongTenantEntityMapper.deleteById(inlongTenantEntity.getId());
- Preconditions.expectTrue(success == 1, "delete failed");
+ Preconditions.expectTrue(success == InlongConstants.AFFECTED_ONE_ROW,
"delete failed");
log.info("success delete inlong tenant name={} by user={}", name,
operator);
return true;
}
+ @Override
+ public Boolean migrate(String groupId, String to) {
+ UserInfo userInfo = LoginUserUtils.getLoginUser();
+ Preconditions.expectTrue(hasPermission(userInfo, to),
+ String.format("user=[%s] has no permission to tenant=[%s]",
userInfo.getName(), to));
+ return doMigrate(groupId, userInfo.getTenant(), to);
+ }
+
+ public Boolean doMigrate(String groupId, String from, String to) {
+ InlongGroupEntity group = groupMapper.selectByGroupId(groupId);
+ Preconditions.expectNotNull(group, String.format("Not find group=%s in
tenant=%s", groupId, from));
+
+ // get related streams, consumes and tag;
+ List<InlongStreamEntity> streamList =
streamMapper.selectByGroupId(groupId);
+ boolean streamMigrateResult = streamList.stream().allMatch(stream ->
migrateStream(stream, from, to));
+ List<InlongConsumeEntity> consumeList =
consumeEntityMapper.selectByGroupId(groupId);
+ boolean consumeMigrateResult = this.migrateConsume(groupId, from, to,
consumeList.size());
+ boolean tagCopyResult =
this.copyTenantTag(group.getInlongClusterTag(), from, to);
+
+ return streamMigrateResult
+ && consumeMigrateResult
+ && tagCopyResult
+ && this.migrateGroup(groupId, from, to);
+ }
+
+ public Boolean migrateStream(InlongStreamEntity stream, String from,
String to) {
+ List<StreamSinkEntity> sinks =
+ sinkMapper.selectByRelatedId(stream.getInlongGroupId(),
stream.getInlongStreamId());
+ List<StreamSourceEntity> sources =
+ sourceMapper.selectByRelatedId(stream.getInlongGroupId(),
stream.getInlongStreamId(), null);
+ boolean sinkMigrateResult = sinks.stream().allMatch(sink ->
migrateStreamSink(sink, from, to));
+ boolean sourceMigrateResult = sources.stream().allMatch(source ->
migrateStreamSource(source, from, to));
+ return sinkMigrateResult && sourceMigrateResult;
+ }
+
+ public Boolean migrateStreamSink(StreamSinkEntity sink, String from,
String to) {
+ String dataNodeName = sink.getDataNodeName();
+ String type = sink.getSinkType();
+ if (StringUtils.isAnyBlank(dataNodeName, type)) {
+ return true;
+ }
+ DataNodeEntity dataNode =
dataNodeEntityMapper.selectByUniqueKey(dataNodeName, type);
+ if (dataNode == null) {
+ return true;
+ }
+
+ String newName = copyDataNode(dataNodeName, type, from, to);
+ sink.setDataNodeName(newName);
+ return sinkMapper.updateByIdSelective(sink) ==
InlongConstants.AFFECTED_ONE_ROW;
+
+ }
+
+ public Boolean migrateStreamSource(StreamSourceEntity source, String from,
String to) {
Review Comment:
Ditto.
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/tenant/InlongTenantServiceImpl.java:
##########
@@ -199,11 +221,122 @@ public Boolean delete(String name) {
throw new BusinessException(errMsg);
}
int success =
inlongTenantEntityMapper.deleteById(inlongTenantEntity.getId());
- Preconditions.expectTrue(success == 1, "delete failed");
+ Preconditions.expectTrue(success == InlongConstants.AFFECTED_ONE_ROW,
"delete failed");
log.info("success delete inlong tenant name={} by user={}", name,
operator);
return true;
}
+ @Override
+ public Boolean migrate(String groupId, String to) {
+ UserInfo userInfo = LoginUserUtils.getLoginUser();
+ Preconditions.expectTrue(hasPermission(userInfo, to),
+ String.format("user=[%s] has no permission to tenant=[%s]",
userInfo.getName(), to));
+ return doMigrate(groupId, userInfo.getTenant(), to);
+ }
+
+ public Boolean doMigrate(String groupId, String from, String to) {
Review Comment:
Ditto.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]