liqingwang commented on code in PR #13887: URL: https://github.com/apache/dolphinscheduler/pull/13887#discussion_r1160520921
########## dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/resource/ResourceCheck.java: ########## @@ -0,0 +1,114 @@ +/* + * 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.api.resource; + +import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ServiceException; +import org.apache.dolphinscheduler.dao.entity.Resource; +import org.apache.dolphinscheduler.service.process.ProcessService; +import org.apache.dolphinscheduler.spi.enums.ResourceType; + +import org.apache.commons.collections.CollectionUtils; + +import java.util.Arrays; +import java.util.List; + +import lombok.Getter; +import lombok.Setter; + +import org.slf4j.Logger; + +import com.google.common.base.Strings; + +@Getter +@Setter +public class ResourceCheck { + + /** + * logger + */ + private Logger logger; + /** + * Resource Type + */ + private ResourceType resourceType; + + /** + * Process Service + */ + private ProcessService processService; + + /** + * need check resourceIds + */ + private String resourceIds; + + /** + * task name + */ + private String taskName; + + /** + * resource exist check + * @param resourceType resource type + * @param processService process service + * @param resourceIds resource ids string with , combine + * @param taskName task name + * @param logger logger + */ + public ResourceCheck(ResourceType resourceType, ProcessService processService, String resourceIds, String taskName, + Logger logger) { + this.resourceType = resourceType; + this.processService = processService; + this.resourceIds = resourceIds; + this.taskName = taskName; + this.logger = logger; + } + + /** + * check all resources exist, + * if contains removed resource throws ServiceException + */ + public void checkAllExist() throws ServiceException { + switch (resourceType) { + case FILE: + if (Strings.isNullOrEmpty(this.resourceIds)) { + logger.error("The given task definition has null resources str, taskName: {}", this.taskName); + return; + } + + Integer[] resourceIdArray = + Arrays.stream(this.resourceIds.split(",")).map(Integer::parseInt).toArray(Integer[]::new); + + if (resourceIdArray.length > 0) { + List<Resource> list = processService.listResourceByIds(resourceIdArray); Review Comment: In our scenario, we are currently using the 3.1.1 version and I don't know about we have refactored about resource center in dev. And for the 3.1.1 version, we encountered this situation. Here are the prerequisites: 1. User can't access third-party storage directly. 2. User only can operate third-party by ds platform. 3. We can't delete the resource that binds online released jobs. process -> task job -> resource table -> third-party storage And if a process is maintained by a team. One member A operates offline this process. Another member B can delete resource binds in this process by ds. Member A re-online this process and got successful. Will throw an exception during runtime. And If we add a pre-check will find this exception when online. -- 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]
