You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@gobblin.apache.org by GitBox <gi...@apache.org> on 2019/11/04 19:06:44 UTC

[GitHub] [incubator-gobblin] zxcware commented on a change in pull request #2755: [GOBBLIN-897] adds local FS spec executor to write jobs to a local dir

zxcware commented on a change in pull request #2755: [GOBBLIN-897] adds local FS spec executor to write jobs to a local dir
URL: https://github.com/apache/incubator-gobblin/pull/2755#discussion_r342217928
 
 

 ##########
 File path: gobblin-runtime/src/main/java/org/apache/gobblin/runtime/spec_executorInstance/LocalFsSpecProducer.java
 ##########
 @@ -0,0 +1,106 @@
+/*
+ * 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.runtime.spec_executorInstance;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.typesafe.config.Config;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.Future;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.gobblin.runtime.api.JobSpec;
+import org.apache.gobblin.runtime.api.Spec;
+import org.apache.gobblin.runtime.api.SpecExecutor;
+import org.apache.gobblin.runtime.api.SpecProducer;
+import org.apache.gobblin.util.CompletedFuture;
+import org.apache.gobblin.util.ConfigUtils;
+
+
+/**
+ * An implementation of {@link SpecProducer} that produces {@link JobSpec}s to the {@value #LOCAL_FS_PRODUCER_PATH_KEY}
+ */
+@Slf4j
+public class LocalFsSpecProducer implements SpecProducer<Spec> {
+  private String specProducerPath;
+  public static final String LOCAL_FS_PRODUCER_PATH_KEY = "gobblin.cluster.localSpecProducer.dir";
+
+  public LocalFsSpecProducer(Config config) {
+    this.specProducerPath = ConfigUtils.getString(config, LOCAL_FS_PRODUCER_PATH_KEY, "");
+    Preconditions.checkArgument(!Strings.isNullOrEmpty(this.specProducerPath), "Missing argument: " + LOCAL_FS_PRODUCER_PATH_KEY);
+    File parentDir = new File(specProducerPath);
+    if (!parentDir.exists()) {
+      if (parentDir.mkdirs()) {
+        log.info("Creating directory path at {}", this.specProducerPath);
+      }
+    }
+  }
+
+  /** Add a {@link Spec} for execution on {@link org.apache.gobblin.runtime.api.SpecExecutor}.
+   * @param addedSpec*/
+  @Override
+  public Future<?> addSpec(Spec addedSpec) {
+    return writeSpec(addedSpec, SpecExecutor.Verb.ADD);
+  }
+
+  /** Update a {@link Spec} being executed on {@link org.apache.gobblin.runtime.api.SpecExecutor}.
+   * @param updatedSpec*/
+  @Override
+  public Future<?> updateSpec(Spec updatedSpec) {
+    return writeSpec(updatedSpec, SpecExecutor.Verb.UPDATE);
+  }
+
+  private Future<?> writeSpec(Spec spec, SpecExecutor.Verb verb) {
+    if (spec instanceof JobSpec) {
+      String specString = spec.toString();
+      // format the JobSpec to have file of <flowGroup>_<flowName>.job
+      String jobFileName = specString.replace('/', '_').substring(specString.lastIndexOf(':')+2, specString.length()-1) + ".job";
+      try (
+        FileOutputStream fStream = new FileOutputStream(this.specProducerPath + File.separatorChar + jobFileName);
+      ) {
+        ((JobSpec) spec).getConfigAsProperties().store(fStream, null);
+        log.info("Writing job {} to {}", jobFileName, this.specProducerPath);
+        return new CompletedFuture<>(Boolean.TRUE, null);
+      } catch (IOException e) {
+        log.error("Exception encountered when adding Spec {}", spec);
+        return new CompletedFuture<>(Boolean.TRUE, e);
+      }
+    } else {
+      throw new RuntimeException("Unsupported spec type " + spec.getClass());
+    }
+  }
+
+  /** Delete a {@link Spec} being executed on {@link org.apache.gobblin.runtime.api.SpecExecutor}.
+   * @param deletedSpecURI
+   * @param headers*/
+  @Override
+  public Future<?> deleteSpec(URI deletedSpecURI, Properties headers) {
+    return new CompletedFuture<>(Boolean.TRUE, null);
 
 Review comment:
   are we expected to delete the job corresponds to the uri?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services