Search in sources :

Example 1 with Verb

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

the class AvroJobSpecKafkaJobMonitor method parseJobSpec.

/**
 * Creates a {@link JobSpec} or {@link URI} from the {@link AvroJobSpec} record.
 * @param record the record as an {@link AvroJobSpec}
 * @return a {@link JobSpec} or {@link URI} wrapped in a {@link Collection} of {@link Either}
 */
@Override
public Collection<Either<JobSpec, URI>> parseJobSpec(AvroJobSpec record) {
    JobSpec.Builder jobSpecBuilder = JobSpec.builder(record.getUri());
    Properties props = new Properties();
    props.putAll(record.getProperties());
    jobSpecBuilder.withJobCatalogURI(record.getUri()).withVersion(record.getVersion()).withDescription(record.getDescription()).withConfigAsProperties(props);
    if (!record.getTemplateUri().isEmpty()) {
        try {
            jobSpecBuilder.withTemplate(new URI(record.getTemplateUri()));
        } catch (URISyntaxException e) {
            log.error("could not parse template URI " + record.getTemplateUri());
        }
    }
    String verbName = record.getMetadata().get(VERB_KEY);
    Verb verb = Verb.valueOf(verbName);
    JobSpec jobSpec = jobSpecBuilder.build();
    log.info("Parsed job spec " + jobSpec.toString());
    if (verb == Verb.ADD || verb == Verb.UPDATE) {
        return Lists.newArrayList(Either.<JobSpec, URI>left(jobSpec));
    } else {
        return Lists.newArrayList(Either.<JobSpec, URI>right(jobSpec.getUri()));
    }
}
Also used : Verb(org.apache.gobblin.runtime.api.SpecExecutor.Verb) AvroJobSpec(org.apache.gobblin.runtime.job_spec.AvroJobSpec) JobSpec(org.apache.gobblin.runtime.api.JobSpec) URISyntaxException(java.net.URISyntaxException) Properties(java.util.Properties) URI(java.net.URI)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Properties (java.util.Properties)1 JobSpec (org.apache.gobblin.runtime.api.JobSpec)1 Verb (org.apache.gobblin.runtime.api.SpecExecutor.Verb)1 AvroJobSpec (org.apache.gobblin.runtime.job_spec.AvroJobSpec)1