det101 commented on code in PR #17165: URL: https://github.com/apache/dolphinscheduler/pull/17165#discussion_r2086722793
########## dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/executor/logging/LocalLogClient.java: ########## @@ -0,0 +1,91 @@ +/* + * 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.executor.logging; + +import org.apache.dolphinscheduler.dao.entity.TaskInstance; +import org.apache.dolphinscheduler.extract.base.client.Clients; +import org.apache.dolphinscheduler.extract.common.ILogService; +import org.apache.dolphinscheduler.extract.common.transportor.TaskInstanceLogFileDownloadRequest; +import org.apache.dolphinscheduler.extract.common.transportor.TaskInstanceLogFileDownloadResponse; +import org.apache.dolphinscheduler.extract.common.transportor.TaskInstanceLogPageQueryRequest; +import org.apache.dolphinscheduler.extract.common.transportor.TaskInstanceLogPageQueryResponse; + +import org.springframework.stereotype.Component; + +@Component +public class LocalLogClient { + + /** + * Download the complete log of a task instance. + * This method is used to retrieve all log information from the start to the end of a task instance, + * suitable for scenarios where a complete log record is required. + * + * @param taskInstance The task instance object, containing information needed to retrieve the log. + * @return The complete log file download response of the task instance, including log content and metadata. + */ + public TaskInstanceLogFileDownloadResponse getWholeLog(TaskInstance taskInstance) { + return getLocalWholeLog(taskInstance); + } + + /** + * Query a portion of the log of a task instance. + * This method is used to query log information of a task instance in a paginated manner, + * suitable for scenarios where the log content is large and needs to be retrieved in batches. + * + * @param taskInstance The task instance object, containing information needed to retrieve the log. + * @param skipLineNum The number of lines to skip, indicating from which line to start reading the log. + * @param limit The maximum number of lines to read, indicating the maximum number of lines to retrieve in this query. + * @return The partial log query response, including log content within the specified range and metadata. + */ + public TaskInstanceLogPageQueryResponse getPartLog(TaskInstance taskInstance, int skipLineNum, int limit) { + return getLocalPartLog(taskInstance, skipLineNum, limit); + } + + private static TaskInstanceLogFileDownloadResponse getLocalWholeLog(TaskInstance taskInstance) { + TaskInstanceLogFileDownloadRequest request = buildLogFileDownloadRequest(taskInstance); + return getProxyLogService(taskInstance).getTaskInstanceWholeLogFileBytes(request); + } + + private static TaskInstanceLogPageQueryResponse getLocalPartLog(TaskInstance taskInstance, int skipLineNum, + int limit) { + TaskInstanceLogPageQueryRequest request = buildLogPageQueryRequest(taskInstance, skipLineNum, limit); + return getProxyLogService(taskInstance).pageQueryTaskInstanceLog(request); + } + + private static TaskInstanceLogFileDownloadRequest buildLogFileDownloadRequest(TaskInstance taskInstance) { + return new TaskInstanceLogFileDownloadRequest( + taskInstance.getId(), + taskInstance.getLogPath()); + } + + private static TaskInstanceLogPageQueryRequest buildLogPageQueryRequest(TaskInstance taskInstance, int skipLineNum, + int limit) { + return TaskInstanceLogPageQueryRequest.builder() + .taskInstanceId(taskInstance.getId()) + .taskInstanceLogAbsolutePath(taskInstance.getLogPath()) + .skipLineNum(skipLineNum) + .limit(limit) + .build(); + } + + private static ILogService getProxyLogService(TaskInstance taskInstance) { + return Clients + .withService(ILogService.class) + .withHost(taskInstance.getHost()); + } Review Comment: function merged -- 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]
