autumnust commented on a change in pull request #2834: [GOBBLIN-988] Implement LocalFSJobStatusRetriever URL: https://github.com/apache/incubator-gobblin/pull/2834#discussion_r354058351
########## File path: gobblin-service/src/main/java/org/apache/gobblin/service/monitoring/LocalFsJobStatusRetriever.java ########## @@ -0,0 +1,142 @@ +/* + * 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.gobblin.service.monitoring; + +import com.google.common.base.Preconditions; + +import com.google.common.collect.Iterators; +import com.typesafe.config.Config; +import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.gobblin.configuration.State; +import org.apache.gobblin.metastore.StateStore; +import org.apache.gobblin.runtime.spec_executorInstance.LocalFsSpecProducer; +import org.apache.gobblin.service.ExecutionStatus; + +import lombok.extern.slf4j.Slf4j; + + +@Slf4j +public class LocalFsJobStatusRetriever extends JobStatusRetriever { + + public static final String CONF_PREFIX = "localFsJobStatusRetriever"; + private String specProducerPath; + + // Do not use a state store for this implementation, just look at the job folder that @LocalFsSpecProducer writes to + public LocalFsJobStatusRetriever(Config config) { + this.specProducerPath = config.getString(LocalFsSpecProducer.LOCAL_FS_PRODUCER_PATH_KEY); + } + + private Boolean isJobPending(String flowName, String flowGroup, long flowExecutionId) { + // Local FS has no monitor to update job state yet, for now check if standalone is completed with job, and mark as done + // Otherwise the job is pending + try { + String fileName = LocalFsSpecProducer.getJobFileName(new URI(File.separatorChar + flowGroup + File.separatorChar + flowName), String.valueOf(flowExecutionId)); + return new File(this.specProducerPath + File.separatorChar + fileName).exists(); + } catch (URISyntaxException e) { + log.error("URISyntaxException occurred when retrieving job status for flow: {},{}", flowGroup, flowName, e); + } + return false; + } + + private Boolean isJobDone(String flowName, String flowGroup, long flowExecutionId) { + // Local FS has no monitor to update job state yet, for now check if standalone is completed with job, and mark as done + // Otherwise the job is pending + try { + String fileName = LocalFsSpecProducer.getJobFileName(new URI(File.separatorChar + flowGroup + File.separatorChar + flowName), String.valueOf(flowExecutionId)); + return new File(this.specProducerPath + File.separatorChar + fileName + ".done").exists(); + } catch (URISyntaxException e) { + log.error("URISyntaxException occurred when retrieving job status for flow: {},{}", flowGroup, flowName, e); + } + return false; + } + + @Override + public Iterator<JobStatus> getJobStatusesForFlowExecution(String flowName, String flowGroup, long flowExecutionId) { + Preconditions.checkArgument(flowName != null, "FlowName cannot be null"); + Preconditions.checkArgument(flowGroup != null, "FlowGroup cannot be null"); + + // For the FS use case, JobExecutionID == FlowExecutionID + Review comment: additional empty line ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
