caishunfeng commented on code in PR #12076:
URL:
https://github.com/apache/dolphinscheduler/pull/12076#discussion_r1004126885
##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UdfFuncServiceImpl.java:
##########
@@ -117,9 +120,15 @@ public Result<Object> createUdfFunction(User loginUser,
return result;
}
- Resource resource = resourceMapper.selectById(resourceId);
- if (resource == null) {
- logger.error("Resource does not exist, resourceId:{}.",
resourceId);
+ Boolean existResource = false;
+ try {
+ existResource = storageOperate.exists(fullName);
+ } catch (IOException e) {
+ logger.error("AmazonServiceException when checking resource: " +
fullName);
Review Comment:
```suggestion
logger.error("Check resource error: {}", fullName, e);
```
##########
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ResourcesTask.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.dolphinscheduler.dao.entity;
+
+import org.apache.dolphinscheduler.spi.enums.ResourceType;
+
+import lombok.Data;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+@Data
+@TableName("t_ds_relation_resources_task")
+public class ResourcesTask {
+
+ private String fullName;
+
+ @TableId(value = "id", type = IdType.AUTO)
+ private Integer id;
Review Comment:
```suggestion
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String fullName;
```
##########
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ResourceTaskMapper.xml:
##########
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ ~ 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.
+ -->
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ResourceTaskMapper">
+ <sql id="baseSqlV2">
+ ${alias}.id, ${alias}.full_name, ${alias}.task_id, ${alias}.type
+ </sql>
+ <select id="existResourceByTaskIdNFullName" resultType="java.lang.Integer">
+ select
+ id
+ from t_ds_relation_resources_task
+ where full_name = #{fullName} and task_id = #{taskId} limit 1
Review Comment:
Why limit 1 here? The taskId and fullName is not uniq?
##########
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml:
##########
@@ -191,6 +191,22 @@
WHERE td.resource_ids is not null and td.resource_ids != '' and
td.user_id = #{userId}
</select>
+ <select id="queryResourcesInUseWithinResourceList"
resultType="java.util.HashMap">
+ SELECT distinct pd.code,td.resource_ids
+ FROM t_ds_process_task_relation ptr
+ join t_ds_process_definition pd
+ on ptr.process_definition_code=pd.code and
ptr.process_definition_version = pd.version
+ and ptr.project_code=pd.project_code and pd.release_state = 1
+ join t_ds_task_definition td
+ on (ptr.pre_task_code=td.code and ptr.pre_task_version=td.version)
+ or (ptr.post_task_code=td.code and ptr.post_task_version=td.version)
+ WHERE 1 = 1
+ and
+ <foreach item="item" index="index" collection="resourcesArray"
separator=" OR " >
+ td.resource_ids LIKE '%${item}%' and td.resource_ids != ''
+ </foreach>
+ </select>
Review Comment:
This sql is complex, please split it.
Avoid using `or` query, it will miss the index.
##########
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ResourcesTask.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.dolphinscheduler.dao.entity;
+
+import org.apache.dolphinscheduler.spi.enums.ResourceType;
+
+import lombok.Data;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+@Data
+@TableName("t_ds_relation_resources_task")
+public class ResourcesTask {
+
+ private String fullName;
+
+ @TableId(value = "id", type = IdType.AUTO)
+ private Integer id;
+
+ private int taskId;
+
+ private ResourceType type;
+
+ public ResourcesTask(int id, String fullName, int taskId, ResourceType
type) {
+ this.id = id;
+ this.fullName = fullName;
+ this.taskId = taskId;
+ this.type = type;
+ }
+
+ public ResourcesTask(int taskId, String fullName, ResourceType type) {
+ this.taskId = taskId;
+ this.fullName = fullName;
+ this.type = type;
+ }
+
+ @Override
+ public String toString() {
Review Comment:
remove it
--
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]