Search in sources :

Example 1 with SpecNotFoundException

use of org.apache.gobblin.runtime.api.SpecNotFoundException in project incubator-gobblin by apache.

the class NonObservingFSJobCatalog method remove.

/**
 * Allow user to programmatically delete a new JobSpec.
 * This method is designed to be reentrant.
 * @param jobURI The relative Path that specified by user, need to make it into complete path.
 */
@Override
public synchronized void remove(URI jobURI) {
    Preconditions.checkState(state() == State.RUNNING, String.format("%s is not running.", this.getClass().getName()));
    try {
        long startTime = System.currentTimeMillis();
        JobSpec jobSpec = getJobSpec(jobURI);
        Path jobSpecPath = getPathForURI(this.jobConfDirPath, jobURI);
        if (fs.exists(jobSpecPath)) {
            fs.delete(jobSpecPath, false);
            this.mutableMetrics.updateRemoveJobTime(startTime);
        } else {
            LOGGER.warn("No file with URI:" + jobSpecPath + " is found. Deletion failed.");
        }
        this.listeners.onDeleteJob(jobURI, jobSpec.getVersion());
    } catch (IOException e) {
        throw new RuntimeException("When removing a JobConf. file, issues unexpected happen:" + e.getMessage());
    } catch (SpecNotFoundException e) {
        LOGGER.warn("No file with URI:" + jobURI + " is found. Deletion failed.");
    }
}
Also used : Path(org.apache.hadoop.fs.Path) JobSpecNotFoundException(org.apache.gobblin.runtime.api.JobSpecNotFoundException) SpecNotFoundException(org.apache.gobblin.runtime.api.SpecNotFoundException) JobSpec(org.apache.gobblin.runtime.api.JobSpec) IOException(java.io.IOException)

Example 2 with SpecNotFoundException

use of org.apache.gobblin.runtime.api.SpecNotFoundException in project incubator-gobblin by apache.

the class EmbeddedGobblin method runAsync.

/**
 * Launch the Gobblin job asynchronously. This method will return when the Gobblin job has started.
 * @return a {@link JobExecutionDriver}. This object is a future that will resolve when the Gobblin job finishes.
 * @throws TimeoutException if the Gobblin job does not start within the launch timeout.
 */
@NotOnCli
public JobExecutionDriver runAsync() throws TimeoutException, InterruptedException {
    // Run function to distribute jars to workers in distributed mode
    this.distributeJarsFunction.run();
    Config sysProps = ConfigFactory.parseMap(this.builtConfigMap).withFallback(this.defaultSysConfig);
    Config userConfig = ConfigFactory.parseMap(this.userConfigMap);
    JobSpec jobSpec;
    if (this.jobFile.isPresent()) {
        try {
            Path jobFilePath = this.jobFile.get();
            PullFileLoader loader = new PullFileLoader(jobFilePath.getParent(), jobFilePath.getFileSystem(new Configuration()), PullFileLoader.DEFAULT_JAVA_PROPS_PULL_FILE_EXTENSIONS, PullFileLoader.DEFAULT_HOCON_PULL_FILE_EXTENSIONS);
            Config jobConfig = userConfig.withFallback(loader.loadPullFile(jobFilePath, sysProps, false));
            ImmutableFSJobCatalog.JobSpecConverter converter = new ImmutableFSJobCatalog.JobSpecConverter(jobFilePath.getParent(), Optional.<String>absent());
            jobSpec = converter.apply(jobConfig);
        } catch (IOException ioe) {
            throw new RuntimeException("Failed to run embedded Gobblin.", ioe);
        }
    } else {
        Config finalConfig = userConfig.withFallback(sysProps);
        if (this.template != null) {
            try {
                finalConfig = this.template.getResolvedConfig(finalConfig);
            } catch (SpecNotFoundException | JobTemplate.TemplateException exc) {
                throw new RuntimeException(exc);
            }
        }
        jobSpec = this.specBuilder.withConfig(finalConfig).build();
    }
    ResolvedJobSpec resolvedJobSpec;
    try {
        resolvedJobSpec = new ResolvedJobSpec(jobSpec);
    } catch (SpecNotFoundException | JobTemplate.TemplateException exc) {
        throw new RuntimeException("Failed to resolved template.", exc);
    }
    final JobCatalog jobCatalog = new StaticJobCatalog(Optional.of(this.useLog), Lists.<JobSpec>newArrayList(resolvedJobSpec));
    SimpleGobblinInstanceEnvironment instanceEnvironment = new SimpleGobblinInstanceEnvironment("EmbeddedGobblinInstance", this.useLog, getSysConfig());
    StandardGobblinInstanceDriver.Builder builder = new StandardGobblinInstanceDriver.Builder(Optional.<GobblinInstanceEnvironment>of(instanceEnvironment)).withLog(this.useLog).withJobCatalog(jobCatalog).withImmediateJobScheduler();
    for (GobblinInstancePluginFactory plugin : this.plugins) {
        builder.addPlugin(plugin);
    }
    final GobblinInstanceDriver driver = builder.build();
    EmbeddedJobLifecycleListener listener = new EmbeddedJobLifecycleListener(this.useLog);
    driver.registerJobLifecycleListener(listener);
    driver.startAsync();
    boolean started = listener.awaitStarted(this.launchTimeout.getTimeout(), this.launchTimeout.getTimeUnit());
    if (!started) {
        log.warn("Timeout waiting for job to start. Aborting.");
        driver.stopAsync();
        driver.awaitTerminated(this.shutdownTimeout.getTimeout(), this.shutdownTimeout.getTimeUnit());
        throw new TimeoutException("Timeout waiting for job to start.");
    }
    final JobExecutionDriver jobDriver = listener.getJobDriver();
    // Stop the Gobblin instance driver when the job finishes.
    Futures.addCallback(jobDriver, new FutureCallback<JobExecutionResult>() {

        @Override
        public void onSuccess(@Nullable JobExecutionResult result) {
            stopGobblinInstanceDriver();
        }

        @Override
        public void onFailure(Throwable t) {
            stopGobblinInstanceDriver();
        }

        private void stopGobblinInstanceDriver() {
            try {
                driver.stopAsync();
                driver.awaitTerminated(EmbeddedGobblin.this.shutdownTimeout.getTimeout(), EmbeddedGobblin.this.shutdownTimeout.getTimeUnit());
            } catch (TimeoutException te) {
                log.error("Failed to shutdown Gobblin instance driver.");
            }
        }
    });
    return listener.getJobDriver();
}
Also used : ImmutableFSJobCatalog(org.apache.gobblin.runtime.job_catalog.ImmutableFSJobCatalog) Configuration(org.apache.hadoop.conf.Configuration) Config(com.typesafe.config.Config) StandardGobblinInstanceDriver(org.apache.gobblin.runtime.instance.StandardGobblinInstanceDriver) GobblinInstanceDriver(org.apache.gobblin.runtime.api.GobblinInstanceDriver) StandardGobblinInstanceDriver(org.apache.gobblin.runtime.instance.StandardGobblinInstanceDriver) StaticJobCatalog(org.apache.gobblin.runtime.job_catalog.StaticJobCatalog) JobCatalog(org.apache.gobblin.runtime.api.JobCatalog) ImmutableFSJobCatalog(org.apache.gobblin.runtime.job_catalog.ImmutableFSJobCatalog) GobblinInstanceEnvironment(org.apache.gobblin.runtime.api.GobblinInstanceEnvironment) SimpleGobblinInstanceEnvironment(org.apache.gobblin.runtime.instance.SimpleGobblinInstanceEnvironment) SpecNotFoundException(org.apache.gobblin.runtime.api.SpecNotFoundException) StaticJobCatalog(org.apache.gobblin.runtime.job_catalog.StaticJobCatalog) ResolvedJobSpec(org.apache.gobblin.runtime.job_spec.ResolvedJobSpec) GobblinInstancePluginFactory(org.apache.gobblin.runtime.api.GobblinInstancePluginFactory) JobExecutionDriver(org.apache.gobblin.runtime.api.JobExecutionDriver) TimeoutException(java.util.concurrent.TimeoutException) Path(org.apache.hadoop.fs.Path) PullFileLoader(org.apache.gobblin.util.PullFileLoader) IOException(java.io.IOException) SimpleGobblinInstanceEnvironment(org.apache.gobblin.runtime.instance.SimpleGobblinInstanceEnvironment) JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) ResolvedJobSpec(org.apache.gobblin.runtime.job_spec.ResolvedJobSpec) JobSpec(org.apache.gobblin.runtime.api.JobSpec) NotOnCli(org.apache.gobblin.runtime.cli.NotOnCli)

Example 3 with SpecNotFoundException

use of org.apache.gobblin.runtime.api.SpecNotFoundException in project incubator-gobblin by apache.

the class FSSpecStore method getSpec.

@Override
public Spec getSpec(URI specUri, String version) throws IOException, SpecNotFoundException {
    Preconditions.checkArgument(null != specUri, "Spec URI should not be null");
    Preconditions.checkArgument(null != version, "Version should not be null");
    Path specPath = getPathForURI(this.fsSpecStoreDirPath, specUri, version);
    if (!fs.exists(specPath)) {
        throw new SpecNotFoundException(specUri);
    }
    return readSpecFromFile(specPath);
}
Also used : Path(org.apache.hadoop.fs.Path) SpecNotFoundException(org.apache.gobblin.runtime.api.SpecNotFoundException)

Example 4 with SpecNotFoundException

use of org.apache.gobblin.runtime.api.SpecNotFoundException in project incubator-gobblin by apache.

the class FSSpecStore method getSpec.

@Override
public Spec getSpec(URI specUri) throws SpecNotFoundException {
    Preconditions.checkArgument(null != specUri, "Spec URI should not be null");
    Collection<Spec> specs = getAllVersionsOfSpec(specUri);
    Spec highestVersionSpec = null;
    for (Spec spec : specs) {
        if (null == highestVersionSpec) {
            highestVersionSpec = spec;
        } else if (null != spec.getVersion() && spec.getVersion().compareTo(spec.getVersion()) > 0) {
            highestVersionSpec = spec;
        }
    }
    if (null == highestVersionSpec) {
        throw new SpecNotFoundException(specUri);
    }
    return highestVersionSpec;
}
Also used : SpecNotFoundException(org.apache.gobblin.runtime.api.SpecNotFoundException) Spec(org.apache.gobblin.runtime.api.Spec) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec)

Example 5 with SpecNotFoundException

use of org.apache.gobblin.runtime.api.SpecNotFoundException in project incubator-gobblin by apache.

the class SchedulerUtils method resolveTemplate.

private static Properties resolveTemplate(Properties jobProps) throws IOException {
    try {
        if (jobProps.containsKey(ConfigurationKeys.JOB_TEMPLATE_PATH)) {
            Config jobConfig = ConfigUtils.propertiesToConfig(jobProps);
            Properties resolvedProps = ConfigUtils.configToProperties((ResourceBasedJobTemplate.forResourcePath(jobProps.getProperty(ConfigurationKeys.JOB_TEMPLATE_PATH), new PackagedTemplatesJobCatalogDecorator())).getResolvedConfig(jobConfig));
            return resolvedProps;
        } else {
            return jobProps;
        }
    } catch (JobTemplate.TemplateException | SpecNotFoundException | URISyntaxException exc) {
        throw new IOException(exc);
    }
}
Also used : SpecNotFoundException(org.apache.gobblin.runtime.api.SpecNotFoundException) PackagedTemplatesJobCatalogDecorator(org.apache.gobblin.runtime.job_catalog.PackagedTemplatesJobCatalogDecorator) Config(com.typesafe.config.Config) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Properties(java.util.Properties)

Aggregations

SpecNotFoundException (org.apache.gobblin.runtime.api.SpecNotFoundException)10 IOException (java.io.IOException)4 JobSpec (org.apache.gobblin.runtime.api.JobSpec)4 Path (org.apache.hadoop.fs.Path)4 Config (com.typesafe.config.Config)3 ResolvedJobSpec (org.apache.gobblin.runtime.job_spec.ResolvedJobSpec)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 Properties (java.util.Properties)2 FlowSpec (org.apache.gobblin.runtime.api.FlowSpec)2 PackagedTemplatesJobCatalogDecorator (org.apache.gobblin.runtime.job_catalog.PackagedTemplatesJobCatalogDecorator)2 PullFileLoader (org.apache.gobblin.util.PullFileLoader)2 Configuration (org.apache.hadoop.conf.Configuration)2 StringMap (com.linkedin.data.template.StringMap)1 ConfigException (com.typesafe.config.ConfigException)1 ConfigRenderOptions (com.typesafe.config.ConfigRenderOptions)1 ConfigResolveOptions (com.typesafe.config.ConfigResolveOptions)1 Map (java.util.Map)1 TimeoutException (java.util.concurrent.TimeoutException)1 GobblinInstanceDriver (org.apache.gobblin.runtime.api.GobblinInstanceDriver)1