Search in sources :

Example 1 with AvroJobSpec

use of org.apache.gobblin.runtime.job_spec.AvroJobSpec 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)

Example 2 with AvroJobSpec

use of org.apache.gobblin.runtime.job_spec.AvroJobSpec in project incubator-gobblin by apache.

the class SimpleKafkaSpecProducer method deleteSpec.

@Override
public Future<?> deleteSpec(URI deletedSpecURI) {
    AvroJobSpec avroJobSpec = AvroJobSpec.newBuilder().setUri(deletedSpecURI.toString()).setMetadata(ImmutableMap.of(VERB_KEY, SpecExecutor.Verb.DELETE.name())).build();
    log.info("Deleting Spec: " + deletedSpecURI + " using Kafka.");
    return getKafkaProducer().write(_serializer.serializeRecord(avroJobSpec), WriteCallback.EMPTY);
}
Also used : AvroJobSpec(org.apache.gobblin.runtime.job_spec.AvroJobSpec)

Example 3 with AvroJobSpec

use of org.apache.gobblin.runtime.job_spec.AvroJobSpec in project incubator-gobblin by apache.

the class SimpleKafkaSpecProducer method convertToAvroJobSpec.

private AvroJobSpec convertToAvroJobSpec(Spec spec, SpecExecutor.Verb verb) {
    if (spec instanceof JobSpec) {
        JobSpec jobSpec = (JobSpec) spec;
        AvroJobSpec.Builder avroJobSpecBuilder = AvroJobSpec.newBuilder();
        avroJobSpecBuilder.setUri(jobSpec.getUri().toString()).setVersion(jobSpec.getVersion()).setDescription(jobSpec.getDescription()).setProperties(Maps.fromProperties(jobSpec.getConfigAsProperties())).setMetadata(ImmutableMap.of(VERB_KEY, verb.name()));
        if (jobSpec.getTemplateURI().isPresent()) {
            avroJobSpecBuilder.setTemplateUri(jobSpec.getTemplateURI().get().toString());
        }
        return avroJobSpecBuilder.build();
    } else {
        throw new RuntimeException("Unsupported spec type " + spec.getClass());
    }
}
Also used : JobSpec(org.apache.gobblin.runtime.api.JobSpec) AvroJobSpec(org.apache.gobblin.runtime.job_spec.AvroJobSpec) AvroJobSpec(org.apache.gobblin.runtime.job_spec.AvroJobSpec)

Example 4 with AvroJobSpec

use of org.apache.gobblin.runtime.job_spec.AvroJobSpec in project incubator-gobblin by apache.

the class AvroJobSpecDeserializer method configure.

@Override
public void configure(Map<String, ?> configs, boolean isKey) {
    InputStream dummyInputStream = new ByteArrayInputStream(new byte[0]);
    _decoder = DecoderFactory.get().binaryDecoder(dummyInputStream, null);
    _reader = new SpecificDatumReader<AvroJobSpec>(AvroJobSpec.SCHEMA$);
    _versionWriter = new FixedSchemaVersionWriter();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FixedSchemaVersionWriter(org.apache.gobblin.metrics.reporter.util.FixedSchemaVersionWriter) AvroJobSpec(org.apache.gobblin.runtime.job_spec.AvroJobSpec)

Example 5 with AvroJobSpec

use of org.apache.gobblin.runtime.job_spec.AvroJobSpec in project incubator-gobblin by apache.

the class SimpleKafkaSpecConsumer method changedSpecs.

@Override
public Future<? extends List<Pair<SpecExecutor.Verb, Spec>>> changedSpecs() {
    List<Pair<SpecExecutor.Verb, Spec>> changesSpecs = new ArrayList<>();
    initializeWatermarks();
    this.currentPartitionIdx = -1;
    while (!allPartitionsFinished()) {
        if (currentPartitionFinished()) {
            moveToNextPartition();
            continue;
        }
        if (this.messageIterator == null || !this.messageIterator.hasNext()) {
            try {
                this.messageIterator = fetchNextMessageBuffer();
            } catch (Exception e) {
                log.error(String.format("Failed to fetch next message buffer for partition %s. Will skip this partition.", getCurrentPartition()), e);
                moveToNextPartition();
                continue;
            }
            if (this.messageIterator == null || !this.messageIterator.hasNext()) {
                moveToNextPartition();
                continue;
            }
        }
        while (!currentPartitionFinished()) {
            if (!this.messageIterator.hasNext()) {
                break;
            }
            KafkaConsumerRecord nextValidMessage = this.messageIterator.next();
            // until we get to x.
            if (nextValidMessage.getOffset() < _nextWatermark.get(this.currentPartitionIdx)) {
                continue;
            }
            _nextWatermark.set(this.currentPartitionIdx, nextValidMessage.getNextOffset());
            try {
                final AvroJobSpec record;
                if (nextValidMessage instanceof ByteArrayBasedKafkaRecord) {
                    record = decodeRecord((ByteArrayBasedKafkaRecord) nextValidMessage);
                } else if (nextValidMessage instanceof DecodeableKafkaRecord) {
                    record = ((DecodeableKafkaRecord<?, AvroJobSpec>) nextValidMessage).getValue();
                } else {
                    throw new IllegalStateException("Unsupported KafkaConsumerRecord type. The returned record can either be ByteArrayBasedKafkaRecord" + " or DecodeableKafkaRecord");
                }
                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()) {
                    jobSpecBuilder.withTemplate(new URI(record.getTemplateUri()));
                }
                String verbName = record.getMetadata().get(VERB_KEY);
                SpecExecutor.Verb verb = SpecExecutor.Verb.valueOf(verbName);
                changesSpecs.add(new ImmutablePair<SpecExecutor.Verb, Spec>(verb, jobSpecBuilder.build()));
            } catch (Throwable t) {
                log.error("Could not decode record at partition " + this.currentPartitionIdx + " offset " + nextValidMessage.getOffset());
            }
        }
    }
    return new CompletedFuture(changesSpecs, null);
}
Also used : DecodeableKafkaRecord(org.apache.gobblin.kafka.client.DecodeableKafkaRecord) ArrayList(java.util.ArrayList) KafkaConsumerRecord(org.apache.gobblin.kafka.client.KafkaConsumerRecord) AvroJobSpec(org.apache.gobblin.runtime.job_spec.AvroJobSpec) Properties(java.util.Properties) ByteArrayBasedKafkaRecord(org.apache.gobblin.kafka.client.ByteArrayBasedKafkaRecord) URI(java.net.URI) KafkaOffsetRetrievalFailureException(org.apache.gobblin.source.extractor.extract.kafka.KafkaOffsetRetrievalFailureException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SpecExecutor(org.apache.gobblin.runtime.api.SpecExecutor) JobSpec(org.apache.gobblin.runtime.api.JobSpec) AvroJobSpec(org.apache.gobblin.runtime.job_spec.AvroJobSpec) JobSpec(org.apache.gobblin.runtime.api.JobSpec) Spec(org.apache.gobblin.runtime.api.Spec) AvroJobSpec(org.apache.gobblin.runtime.job_spec.AvroJobSpec) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) CompletedFuture(org.apache.gobblin.util.CompletedFuture)

Aggregations

AvroJobSpec (org.apache.gobblin.runtime.job_spec.AvroJobSpec)7 JobSpec (org.apache.gobblin.runtime.api.JobSpec)3 URI (java.net.URI)2 Properties (java.util.Properties)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 Pair (org.apache.commons.lang3.tuple.Pair)1 ByteArrayBasedKafkaRecord (org.apache.gobblin.kafka.client.ByteArrayBasedKafkaRecord)1 DecodeableKafkaRecord (org.apache.gobblin.kafka.client.DecodeableKafkaRecord)1 KafkaConsumerRecord (org.apache.gobblin.kafka.client.KafkaConsumerRecord)1 FixedSchemaVersionWriter (org.apache.gobblin.metrics.reporter.util.FixedSchemaVersionWriter)1 Spec (org.apache.gobblin.runtime.api.Spec)1 SpecExecutor (org.apache.gobblin.runtime.api.SpecExecutor)1 Verb (org.apache.gobblin.runtime.api.SpecExecutor.Verb)1