zhongjiajie commented on code in PR #10823: URL: https://github.com/apache/dolphinscheduler/pull/10823#discussion_r917597944
########## dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/resource_definition.py: ########## @@ -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. + +"""Module resource.""" + +from typing import Optional + +from pydolphinscheduler.core.base import Base +from pydolphinscheduler.java_gateway import launch_gateway + + +class ResourceDefinition(Base): + """resource object, will define the resources that you want to create or update. + + :param user: The user who create or update resource. + :param name: The name of resource.Do not include file suffixes. + :param suffix: The suffix of resource. + :param current_dir: The folder where the resource resides. + :param content: The description of resource. + :param description: The description of resource. + """ + + _DEFINE_ATTR = {"user", "name", "suffix", "current_dir", "content", "description"} + + def __init__( + self, + user: str, Review Comment: why we need `user` here? and how can we use `resource`? Does we have to use it alone instead of use it in the `process_definition`? ########## dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/resource_definition.py: ########## @@ -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. + +"""Module resource.""" + +from typing import Optional + +from pydolphinscheduler.core.base import Base +from pydolphinscheduler.java_gateway import launch_gateway + + +class ResourceDefinition(Base): + """resource object, will define the resources that you want to create or update. + + :param user: The user who create or update resource. + :param name: The name of resource.Do not include file suffixes. + :param suffix: The suffix of resource. + :param current_dir: The folder where the resource resides. + :param content: The description of resource. + :param description: The description of resource. + """ + + _DEFINE_ATTR = {"user", "name", "suffix", "current_dir", "content", "description"} + + def __init__( + self, + user: str, + name: str, + suffix: str, Review Comment: I wonder, can we combine `name` and `suffix` to reduce our user's job? and extract the suffix in our python code or python gateway code? ########## dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java: ########## @@ -547,6 +547,49 @@ public Map<String, Object> queryResourcesFileInfo(String userName, String fullNa return result; } + /** + * create or update resource. + * If the folder is not already created, it will be + * + * @param userName user who create or update resource + * @param resourceDir The folder where the resource resides. + * @param resourceName The name of resource.Do not include file suffixes. + * @param resourceSuffix suffix of resource + * @param description description of resource + * @param resourceContent content of resource + * @return id of resource + */ + public Integer createOrUpdateResource( Review Comment: can we migrate all those main logic codes into https://github.com/apache/dolphinscheduler/blob/a6154220dc9fd78a894f9fc47c78378cba1d03cd/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L1581 just like https://github.com/apache/dolphinscheduler/blob/a6154220dc9fd78a894f9fc47c78378cba1d03cd/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java#L352-L374 I find in we can add service in `ResourcesServiceImpl` will make our code easier to maintain. And with the pre review comment, maybe we only need to check whether the directory or file exists in https://github.com/apache/dolphinscheduler/blob/a6154220dc9fd78a894f9fc47c78378cba1d03cd/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java#L329-L332 and create directory or file if not exists ########## dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/resource_definition.py: ########## @@ -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. + +"""Module resource.""" + +from typing import Optional + +from pydolphinscheduler.core.base import Base +from pydolphinscheduler.java_gateway import launch_gateway + + +class ResourceDefinition(Base): + """resource object, will define the resources that you want to create or update. + + :param user: The user who create or update resource. + :param name: The name of resource.Do not include file suffixes. + :param suffix: The suffix of resource. + :param current_dir: The folder where the resource resides. + :param content: The description of resource. + :param description: The description of resource. + """ + + _DEFINE_ATTR = {"user", "name", "suffix", "current_dir", "content", "description"} + + def __init__( + self, + user: str, + name: str, + suffix: str, Review Comment: And I think maybe we can directly use a path like `/dir1/dir2/file.py` in our `resource` class object, and inside our code(python or java code) we parser it to `dir=/dir1/dir2`, `name=file` and `suffix=py`. which more easier to use in users side -- 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]
