You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampark.apache.org by be...@apache.org on 2023/03/19 07:34:30 UTC

[incubator-streampark] branch yarnQueue created (now 2a8d7ab0d)

This is an automated email from the ASF dual-hosted git repository.

benjobs pushed a change to branch yarnQueue
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git


      at 2a8d7ab0d [Improve] yarnQueue check exists improvement

This branch includes the following new commits:

     new 2a8d7ab0d [Improve] yarnQueue check exists improvement

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-streampark] 01/01: [Improve] yarnQueue check exists improvement

Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

benjobs pushed a commit to branch yarnQueue
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git

commit 2a8d7ab0db7436b5e54bc31707e2ea166e953ec6
Author: benjobs <be...@apache.org>
AuthorDate: Sun Mar 19 15:32:53 2023 +0800

    [Improve] yarnQueue check exists improvement
---
 .../console/core/mapper/YarnQueueMapper.java          |  2 ++
 .../core/service/impl/YarnQueueServiceImpl.java       | 19 +++++++++----------
 .../main/resources/mapper/core/YarnQueueMapper.xml    | 15 +++++++++++++++
 3 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/mapper/YarnQueueMapper.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/mapper/YarnQueueMapper.java
index ffa4eed6c..5176d1b5c 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/mapper/YarnQueueMapper.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/mapper/YarnQueueMapper.java
@@ -28,4 +28,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 /** Yarn queue mapper definition. */
 public interface YarnQueueMapper extends BaseMapper<YarnQueue> {
   IPage<YarnQueue> findQueues(Page<YarnQueue> page, @Param("yarnQueue") YarnQueue yarnQueue);
+
+  boolean existsByQueueLabel(@Param("yarnQueue") YarnQueue yarnQueue);
 }
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/YarnQueueServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/YarnQueueServiceImpl.java
index 7ccc1d76f..f8a192c57 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/YarnQueueServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/YarnQueueServiceImpl.java
@@ -34,7 +34,6 @@ import org.apache.streampark.console.core.utils.YarnQueueLabelExpression;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -65,8 +64,6 @@ public class YarnQueueServiceImpl extends ServiceImpl<YarnQueueMapper, YarnQueue
       "The queue label existed already. Try on a new queue label, please.";
   public static final String QUEUE_EMPTY_HINT = "Yarn queue label mustn't be empty.";
   public static final String QUEUE_AVAILABLE_HINT = "The queue label is available.";
-  public static final String NO_NEED_UPDATE_HINT = "Same data need not to update.";
-
   @Autowired private ApplicationService applicationService;
   @Autowired private FlinkClusterService flinkClusterService;
 
@@ -105,12 +102,9 @@ public class YarnQueueServiceImpl extends ServiceImpl<YarnQueueMapper, YarnQueue
       responseResult.setMsg(ERR_FORMAT_HINTS);
       return responseResult;
     }
-    boolean existed =
-        getBaseMapper()
-            .exists(
-                new LambdaQueryWrapper<YarnQueue>()
-                    .eq(YarnQueue::getTeamId, yarnQueue.getTeamId())
-                    .eq(YarnQueue::getQueueLabel, yarnQueue.getQueueLabel()));
+
+    boolean existed = this.baseMapper.existsByQueueLabel(yarnQueue);
+
     if (existed) {
       responseResult.setStatus(1);
       responseResult.setMsg(QUEUE_EXISTED_IN_TEAM_HINT);
@@ -132,16 +126,21 @@ public class YarnQueueServiceImpl extends ServiceImpl<YarnQueueMapper, YarnQueue
   public void updateYarnQueue(YarnQueue yarnQueue) {
 
     YarnQueue queueFromDB = getYarnQueueByIdWithPreconditions(yarnQueue);
+
+    // 1) no data to update
     if (StringUtils.equals(yarnQueue.getQueueLabel(), queueFromDB.getQueueLabel())
         && StringUtils.equals(yarnQueue.getDescription(), queueFromDB.getDescription())) {
-      throw new ApiAlertException(NO_NEED_UPDATE_HINT);
+      return;
     }
+
+    // 2 update description
     if (StringUtils.equals(yarnQueue.getQueueLabel(), queueFromDB.getQueueLabel())) {
       queueFromDB.setDescription(yarnQueue.getDescription());
       updateById(queueFromDB);
       return;
     }
 
+    // 3 update yarnQueue
     ApiAlertException.throwIfFalse(
         YarnQueueLabelExpression.isValid(yarnQueue.getQueueLabel()), ERR_FORMAT_HINTS);
 
diff --git a/streampark-console/streampark-console-service/src/main/resources/mapper/core/YarnQueueMapper.xml b/streampark-console/streampark-console-service/src/main/resources/mapper/core/YarnQueueMapper.xml
index d9d5ed959..35366ae22 100644
--- a/streampark-console/streampark-console-service/src/main/resources/mapper/core/YarnQueueMapper.xml
+++ b/streampark-console/streampark-console-service/src/main/resources/mapper/core/YarnQueueMapper.xml
@@ -46,4 +46,19 @@
             order by ${yarnQueue.sortField} ${yarnQueue.sortOrder}
         </if>
     </select>
+
+    <select id="existsByQueueLabel" resultType="java.lang.Boolean" parameterType="org.apache.streampark.console.core.entity.YarnQueue">
+        select count(1)
+        from t_yarn_queue
+        <where>
+            team_id = #{yarnQueue.teamId}
+            and
+            queue_label = #{yarnQueue.queueLabel}
+            <if test="yarnQueue.id != null">
+                and id &lt;&gt; #{yarnQueue.id}
+            </if>
+        </where>
+        limit 1
+    </select>
+
 </mapper>