Search in sources :

Example 1 with JobSpecNotFoundException

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

the class FSJobCatalog method put.

/**
 * Allow user to programmatically add a new JobSpec.
 * The method will materialized the jobSpec into real file.
 *
 * @param jobSpec The target JobSpec Object to be materialized.
 *                Noted that the URI return by getUri is a relative path.
 */
@Override
public synchronized void put(JobSpec jobSpec) {
    Preconditions.checkState(state() == State.RUNNING, String.format("%s is not running.", this.getClass().getName()));
    Preconditions.checkNotNull(jobSpec);
    try {
        long startTime = System.currentTimeMillis();
        Path jobSpecPath = getPathForURI(this.jobConfDirPath, jobSpec.getUri());
        materializedJobSpec(jobSpecPath, jobSpec, this.fs);
        this.mutableMetrics.updatePutJobTime(startTime);
    } catch (IOException e) {
        throw new RuntimeException("When persisting a new JobSpec, unexpected issues happen:" + e.getMessage());
    } catch (JobSpecNotFoundException e) {
        throw new RuntimeException("When replacing a existed JobSpec, unexpected issue happen:" + e.getMessage());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) JobSpecNotFoundException(org.apache.gobblin.runtime.api.JobSpecNotFoundException) IOException(java.io.IOException)

Example 2 with JobSpecNotFoundException

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

the class TestMutableCachingJobCatalog method test.

@Test
public void test() throws Exception {
    InMemoryJobCatalog baseCat = new InMemoryJobCatalog(Optional.<Logger>of(LoggerFactory.getLogger("baseCat")));
    baseCat.startAsync();
    baseCat.awaitRunning(2, TimeUnit.SECONDS);
    MutableCachingJobCatalog cachedCat = new MutableCachingJobCatalog(baseCat, Optional.<Logger>of(LoggerFactory.getLogger("cachedCat")));
    JobCatalogListener l = Mockito.mock(JobCatalogListener.class);
    cachedCat.addListener(l);
    cachedCat.startAsync();
    cachedCat.awaitRunning(10, TimeUnit.SECONDS);
    JobSpec js1_1 = JobSpec.builder("test:job1").withVersion("1").build();
    JobSpec js1_2 = JobSpec.builder("test:job1").withVersion("2").build();
    JobSpec js1_3 = JobSpec.builder("test:job1").withVersion("3").build();
    URI jsURI = new URI("test:job1");
    baseCat.put(js1_1);
    JobSpec res = cachedCat.getJobSpec(new URI("test:job1"));
    Assert.assertEquals(res, js1_1);
    baseCat.put(js1_2);
    res = cachedCat.getJobSpec(jsURI);
    Assert.assertEquals(res, js1_2);
    baseCat.remove(jsURI);
    try {
        cachedCat.getJobSpec(jsURI);
        Assert.fail("Expected JobSpecNotFoundException");
    } catch (JobSpecNotFoundException e) {
        Assert.assertEquals(e.getMissingJobSpecURI(), jsURI);
    }
    cachedCat.removeListener(l);
    cachedCat.put(js1_3);
    res = cachedCat.getJobSpec(jsURI);
    Assert.assertEquals(res, js1_3);
    res = baseCat.getJobSpec(jsURI);
    Assert.assertEquals(res, js1_3);
    cachedCat.remove(jsURI);
    try {
        cachedCat.getJobSpec(jsURI);
        Assert.fail("Expected JobSpecNotFoundException");
    } catch (JobSpecNotFoundException e) {
        Assert.assertEquals(e.getMissingJobSpecURI(), jsURI);
    }
    try {
        baseCat.getJobSpec(jsURI);
        Assert.fail("Expected JobSpecNotFoundException");
    } catch (JobSpecNotFoundException e) {
        Assert.assertEquals(e.getMissingJobSpecURI(), jsURI);
    }
    Mockito.verify(l).onAddJob(Mockito.eq(js1_1));
    Mockito.verify(l).onUpdateJob(Mockito.eq(js1_2));
    Mockito.verify(l).onDeleteJob(Mockito.eq(js1_2.getUri()), Mockito.eq(js1_2.getVersion()));
    Mockito.verifyNoMoreInteractions(l);
    cachedCat.stopAsync();
    cachedCat.awaitTerminated(10, TimeUnit.SECONDS);
    baseCat.stopAsync();
    baseCat.awaitTerminated(2, TimeUnit.SECONDS);
}
Also used : JobSpecNotFoundException(org.apache.gobblin.runtime.api.JobSpecNotFoundException) JobCatalogListener(org.apache.gobblin.runtime.api.JobCatalogListener) JobSpec(org.apache.gobblin.runtime.api.JobSpec) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 3 with JobSpecNotFoundException

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

the class NonObservingFSJobCatalog method put.

/**
 * Allow user to programmatically add a new JobSpec.
 * The method will materialized the jobSpec into real file.
 *
 * @param jobSpec The target JobSpec Object to be materialized.
 *                Noted that the URI return by getUri is a relative path.
 */
@Override
public synchronized void put(JobSpec jobSpec) {
    Preconditions.checkState(state() == State.RUNNING, String.format("%s is not running.", this.getClass().getName()));
    Preconditions.checkNotNull(jobSpec);
    try {
        long startTime = System.currentTimeMillis();
        Path jobSpecPath = getPathForURI(this.jobConfDirPath, jobSpec.getUri());
        boolean isUpdate = fs.exists(jobSpecPath);
        materializedJobSpec(jobSpecPath, jobSpec, this.fs);
        this.mutableMetrics.updatePutJobTime(startTime);
        if (isUpdate) {
            this.listeners.onUpdateJob(jobSpec);
        } else {
            this.listeners.onAddJob(jobSpec);
        }
    } catch (IOException e) {
        throw new RuntimeException("When persisting a new JobSpec, unexpected issues happen:" + e.getMessage());
    } catch (JobSpecNotFoundException e) {
        throw new RuntimeException("When replacing a existed JobSpec, unexpected issue happen:" + e.getMessage());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) JobSpecNotFoundException(org.apache.gobblin.runtime.api.JobSpecNotFoundException) IOException(java.io.IOException)

Aggregations

JobSpecNotFoundException (org.apache.gobblin.runtime.api.JobSpecNotFoundException)3 IOException (java.io.IOException)2 Path (org.apache.hadoop.fs.Path)2 URI (java.net.URI)1 JobCatalogListener (org.apache.gobblin.runtime.api.JobCatalogListener)1 JobSpec (org.apache.gobblin.runtime.api.JobSpec)1 Test (org.testng.annotations.Test)1