Skip to content
Snippets Groups Projects
Commit 932ae9e1 authored by Sören Henning's avatar Sören Henning
Browse files

Merge branch 'master' into benchmark-smoke-tests

parents 59bff5c3 3bdc9c14
No related branches found
No related tags found
1 merge request!232Add smoke tests for benchmark
Pipeline #6350 failed
Showing
with 65 additions and 109 deletions
...@@ -61,7 +61,7 @@ cleanup_settings_version=2 ...@@ -61,7 +61,7 @@ cleanup_settings_version=2
eclipse.preferences.version=1 eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_CAU-SE-Style formatter_profile=_CAU-SE-Style
formatter_settings_version=15 formatter_settings_version=21
org.eclipse.jdt.ui.ignorelowercasenames=true org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=; org.eclipse.jdt.ui.importorder=;
org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.ondemandthreshold=99
......
...@@ -61,7 +61,7 @@ cleanup_settings_version=2 ...@@ -61,7 +61,7 @@ cleanup_settings_version=2
eclipse.preferences.version=1 eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_CAU-SE-Style formatter_profile=_CAU-SE-Style
formatter_settings_version=15 formatter_settings_version=21
org.eclipse.jdt.ui.ignorelowercasenames=true org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=; org.eclipse.jdt.ui.importorder=;
org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.ondemandthreshold=99
......
...@@ -61,7 +61,7 @@ cleanup_settings_version=2 ...@@ -61,7 +61,7 @@ cleanup_settings_version=2
eclipse.preferences.version=1 eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_CAU-SE-Style formatter_profile=_CAU-SE-Style
formatter_settings_version=15 formatter_settings_version=21
org.eclipse.jdt.ui.ignorelowercasenames=true org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=; org.eclipse.jdt.ui.importorder=;
org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.ondemandthreshold=99
......
...@@ -2,4 +2,6 @@ plugins { ...@@ -2,4 +2,6 @@ plugins {
id 'theodolite.beam' id 'theodolite.beam'
} }
dependencies {
implementation ('io.confluent:kafka-streams-avro-serde:5.3.2')
}
...@@ -16,8 +16,8 @@ import titan.ccp.model.records.ActivePowerRecord; ...@@ -16,8 +16,8 @@ import titan.ccp.model.records.ActivePowerRecord;
/** /**
* Duplicates the Kv containing the (Children,Parents) pair as a flat map. * Duplicates the Kv containing the (Children,Parents) pair as a flat map.
*/ */
public class DuplicateAsFlatMap extends DoFn public class DuplicateAsFlatMap
<KV<String, ActivePowerRecord>, KV<SensorParentKey, ActivePowerRecord>> { extends DoFn<KV<String, ActivePowerRecord>, KV<SensorParentKey, ActivePowerRecord>> {
private static final long serialVersionUID = -5132355515723961647L; private static final long serialVersionUID = -5132355515723961647L;
@StateId("parents") @StateId("parents")
private final StateSpec<ValueState<Set<String>>> parents = StateSpecs.value();// NOPMD private final StateSpec<ValueState<Set<String>>> parents = StateSpecs.value();// NOPMD
...@@ -33,16 +33,17 @@ public class DuplicateAsFlatMap extends DoFn ...@@ -33,16 +33,17 @@ public class DuplicateAsFlatMap extends DoFn
* Generate a KV-pair for every child-parent match. * Generate a KV-pair for every child-parent match.
*/ */
@ProcessElement @ProcessElement
public void processElement(@Element final KV<String, ActivePowerRecord> kv, public void processElement(
@Element final KV<String, ActivePowerRecord> kv,
final OutputReceiver<KV<SensorParentKey, ActivePowerRecord>> out, final OutputReceiver<KV<SensorParentKey, ActivePowerRecord>> out,
@StateId("parents") final ValueState<Set<String>> state, @StateId("parents") final ValueState<Set<String>> state,
final ProcessContext c) { final ProcessContext c) {
final ActivePowerRecord record = kv.getValue() == null ? null : kv.getValue(); final ActivePowerRecord record = kv.getValue() == null ? null : kv.getValue();
final Set<String> newParents = final Set<String> newParents =
c.sideInput(childParentPairMap).get(kv.getKey()) == null c.sideInput(this.childParentPairMap).get(kv.getKey()) == null
? Collections.emptySet() ? Collections.emptySet()
: c.sideInput(childParentPairMap).get(kv.getKey()); : c.sideInput(this.childParentPairMap).get(kv.getKey());
final Set<String> oldParents = final Set<String> oldParents =
MoreObjects.firstNonNull(state.read(), Collections.emptySet()); MoreObjects.firstNonNull(state.read(), Collections.emptySet());
// Forward new Pairs if they exist // Forward new Pairs if they exist
......
...@@ -66,8 +66,8 @@ public final class Uc4BeamPipeline extends AbstractPipeline { ...@@ -66,8 +66,8 @@ public final class Uc4BeamPipeline extends AbstractPipeline {
final Duration gracePeriod = final Duration gracePeriod =
Duration.standardSeconds(config.getInt(ConfigurationKeys.GRACE_PERIOD_MS)); Duration.standardSeconds(config.getInt(ConfigurationKeys.GRACE_PERIOD_MS));
// Build kafka configuration // Build Kafka configuration
final Map<String, Object> consumerConfig = this.buildConsumerConfig(); final Map<String, Object> consumerConfig = super.buildConsumerConfig();
final Map<String, Object> configurationConfig = this.configurationConfig(config); final Map<String, Object> configurationConfig = this.configurationConfig(config);
// Set Coders for Classes that will be distributed // Set Coders for Classes that will be distributed
...@@ -77,25 +77,34 @@ public final class Uc4BeamPipeline extends AbstractPipeline { ...@@ -77,25 +77,34 @@ public final class Uc4BeamPipeline extends AbstractPipeline {
// Read from Kafka // Read from Kafka
// ActivePowerRecords // ActivePowerRecords
final KafkaActivePowerTimestampReader kafkaActivePowerRecordReader = final KafkaActivePowerTimestampReader kafkaActivePowerRecordReader =
new KafkaActivePowerTimestampReader(this.bootstrapServer, this.inputTopic, consumerConfig); new KafkaActivePowerTimestampReader(
this.bootstrapServer,
this.inputTopic,
consumerConfig);
// Configuration Events // Configuration Events
final KafkaGenericReader<Event, String> kafkaConfigurationReader = final KafkaGenericReader<Event, String> kafkaConfigurationReader =
new KafkaGenericReader<>( new KafkaGenericReader<>(
this.bootstrapServer, configurationTopic, configurationConfig, this.bootstrapServer,
EventDeserializer.class, StringDeserializer.class); configurationTopic,
configurationConfig,
// Transform into AggregatedActivePowerRecords into ActivePowerRecords EventDeserializer.class,
final AggregatedToActive aggregatedToActive = new AggregatedToActive(); StringDeserializer.class);
// Write to Kafka // Write to Kafka
final KafkaWriterTransformation<AggregatedActivePowerRecord> kafkaOutput = final KafkaWriterTransformation<AggregatedActivePowerRecord> kafkaOutput =
new KafkaWriterTransformation<>( new KafkaWriterTransformation<>(
this.bootstrapServer, outputTopic, AggregatedActivePowerRecordSerializer.class); this.bootstrapServer,
outputTopic,
AggregatedActivePowerRecordSerializer.class,
super.buildProducerConfig());
final KafkaWriterTransformation<AggregatedActivePowerRecord> kafkaFeedback = final KafkaWriterTransformation<AggregatedActivePowerRecord> kafkaFeedback =
new KafkaWriterTransformation<>( new KafkaWriterTransformation<>(
this.bootstrapServer, feedbackTopic, AggregatedActivePowerRecordSerializer.class); this.bootstrapServer,
feedbackTopic,
AggregatedActivePowerRecordSerializer.class,
super.buildProducerConfig());
// Apply pipeline transformations // Apply pipeline transformations
final PCollection<KV<String, ActivePowerRecord>> values = this final PCollection<KV<String, ActivePowerRecord>> values = this
...@@ -115,7 +124,10 @@ public final class Uc4BeamPipeline extends AbstractPipeline { ...@@ -115,7 +124,10 @@ public final class Uc4BeamPipeline extends AbstractPipeline {
.withBootstrapServers(this.bootstrapServer) .withBootstrapServers(this.bootstrapServer)
.withTopic(feedbackTopic) .withTopic(feedbackTopic)
.withKeyDeserializer(StringDeserializer.class) .withKeyDeserializer(StringDeserializer.class)
.withValueDeserializer(AggregatedActivePowerRecordDeserializer.class) .withValueDeserializerAndCoder(
AggregatedActivePowerRecordDeserializer.class,
AvroCoder.of(AggregatedActivePowerRecord.class))
.withConsumerConfigUpdates(consumerConfig)
.withTimestampPolicyFactory( .withTimestampPolicyFactory(
(tp, previousWaterMark) -> new AggregatedActivePowerRecordEventTimePolicy( (tp, previousWaterMark) -> new AggregatedActivePowerRecordEventTimePolicy(
previousWaterMark)) previousWaterMark))
...@@ -123,11 +135,12 @@ public final class Uc4BeamPipeline extends AbstractPipeline { ...@@ -123,11 +135,12 @@ public final class Uc4BeamPipeline extends AbstractPipeline {
.apply("Apply Windows", Window.into(FixedWindows.of(duration))) .apply("Apply Windows", Window.into(FixedWindows.of(duration)))
// Convert into the correct data format // Convert into the correct data format
.apply("Convert AggregatedActivePowerRecord to ActivePowerRecord", .apply("Convert AggregatedActivePowerRecord to ActivePowerRecord",
MapElements.via(aggregatedToActive)) MapElements.via(new AggregatedToActive()))
.apply("Set trigger for feedback", Window .apply("Set trigger for feedback", Window
.<KV<String, ActivePowerRecord>>configure() .<KV<String, ActivePowerRecord>>configure()
.triggering(Repeatedly.forever( .triggering(Repeatedly.forever(
AfterProcessingTime.pastFirstElementInPane() AfterProcessingTime
.pastFirstElementInPane()
.plusDelayOf(triggerDelay))) .plusDelayOf(triggerDelay)))
.withAllowedLateness(gracePeriod) .withAllowedLateness(gracePeriod)
.discardingFiredPanes()); .discardingFiredPanes());
...@@ -170,17 +183,13 @@ public final class Uc4BeamPipeline extends AbstractPipeline { ...@@ -170,17 +183,13 @@ public final class Uc4BeamPipeline extends AbstractPipeline {
.accumulatingFiredPanes()) .accumulatingFiredPanes())
.apply(View.asMap()); .apply(View.asMap());
final FilterNullValues filterNullValues = new FilterNullValues();
// Build pairs of every sensor reading and parent // Build pairs of every sensor reading and parent
final PCollection<KV<SensorParentKey, ActivePowerRecord>> flatMappedValues = final PCollection<KV<SensorParentKey, ActivePowerRecord>> flatMappedValues =
inputCollection.apply( inputCollection.apply(
"Duplicate as flatMap", "Duplicate as flatMap",
ParDo.of(new DuplicateAsFlatMap(childParentPairMap)) ParDo.of(new DuplicateAsFlatMap(childParentPairMap)).withSideInputs(childParentPairMap))
.withSideInputs(childParentPairMap))
.apply("Filter only latest changes", Latest.perKey()) .apply("Filter only latest changes", Latest.perKey())
.apply("Filter out null values", .apply("Filter out null values", Filter.by(new FilterNullValues()));
Filter.by(filterNullValues));
final SetIdForAggregated setIdForAggregated = new SetIdForAggregated(); final SetIdForAggregated setIdForAggregated = new SetIdForAggregated();
final SetKeyToGroup setKeyToGroup = new SetKeyToGroup(); final SetKeyToGroup setKeyToGroup = new SetKeyToGroup();
...@@ -204,8 +213,7 @@ public final class Uc4BeamPipeline extends AbstractPipeline { ...@@ -204,8 +213,7 @@ public final class Uc4BeamPipeline extends AbstractPipeline {
aggregations.apply("Write to aggregation results", kafkaOutput); aggregations.apply("Write to aggregation results", kafkaOutput);
aggregations aggregations.apply("Write to feedback topic", kafkaFeedback);
.apply("Write to feedback topic", kafkaFeedback);
} }
...@@ -217,13 +225,14 @@ public final class Uc4BeamPipeline extends AbstractPipeline { ...@@ -217,13 +225,14 @@ public final class Uc4BeamPipeline extends AbstractPipeline {
*/ */
public Map<String, Object> configurationConfig(final Configuration config) { public Map<String, Object> configurationConfig(final Configuration config) {
final Map<String, Object> consumerConfig = new HashMap<>(); final Map<String, Object> consumerConfig = new HashMap<>();
consumerConfig.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, consumerConfig.put(
ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG,
config.getString(ConfigurationKeys.ENABLE_AUTO_COMMIT_CONFIG)); config.getString(ConfigurationKeys.ENABLE_AUTO_COMMIT_CONFIG));
consumerConfig.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, consumerConfig.put(
config ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
.getString(ConfigurationKeys.AUTO_OFFSET_RESET_CONFIG)); config.getString(ConfigurationKeys.AUTO_OFFSET_RESET_CONFIG));
consumerConfig.put(
consumerConfig.put(ConsumerConfig.GROUP_ID_CONFIG, config ConsumerConfig.GROUP_ID_CONFIG, config
.getString(ConfigurationKeys.APPLICATION_NAME) + "-configuration"); .getString(ConfigurationKeys.APPLICATION_NAME) + "-configuration");
return consumerConfig; return consumerConfig;
} }
......
...@@ -11,8 +11,7 @@ import org.apache.beam.sdk.coders.CoderException; ...@@ -11,8 +11,7 @@ import org.apache.beam.sdk.coders.CoderException;
import titan.ccp.model.records.AggregatedActivePowerRecord; import titan.ccp.model.records.AggregatedActivePowerRecord;
/** /**
* Wrapper Class that encapsulates a AggregatedActivePowerRecord Serde in a * {@link Coder} for an {@link AggregatedActivePowerRecord}.
* org.apache.beam.sdk.coders.Coder.
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class AggregatedActivePowerRecordCoder extends Coder<AggregatedActivePowerRecord> public class AggregatedActivePowerRecordCoder extends Coder<AggregatedActivePowerRecord>
...@@ -51,7 +50,7 @@ public class AggregatedActivePowerRecordCoder extends Coder<AggregatedActivePowe ...@@ -51,7 +50,7 @@ public class AggregatedActivePowerRecordCoder extends Coder<AggregatedActivePowe
@Override @Override
public void verifyDeterministic() throws NonDeterministicException { public void verifyDeterministic() throws NonDeterministicException {
if (!DETERMINISTIC) { if (!DETERMINISTIC) {
throw new NonDeterministicException(this, "This class should be deterministic!"); throw new NonDeterministicException(this, "This class should be deterministic.");
} }
} }
} }
package serialization; package serialization;
import java.io.ByteArrayInputStream; import io.confluent.kafka.streams.serdes.avro.SpecificAvroDeserializer;
import java.io.IOException;
import org.apache.beam.sdk.coders.AvroCoder;
import org.apache.kafka.common.serialization.Deserializer; import org.apache.kafka.common.serialization.Deserializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import titan.ccp.model.records.AggregatedActivePowerRecord; import titan.ccp.model.records.AggregatedActivePowerRecord;
/** /**
* Wrapper Class that encapsulates a IMonitoringRecordSerde.serializer in a Deserializer * {@link Deserializer} for an {@link AggregatedActivePowerRecord}.
*/ */
public class AggregatedActivePowerRecordDeserializer public class AggregatedActivePowerRecordDeserializer
implements Deserializer<AggregatedActivePowerRecord> { extends SpecificAvroDeserializer<AggregatedActivePowerRecord> {
private static final Logger LOGGER =
LoggerFactory.getLogger(AggregatedActivePowerRecordDeserializer.class);
private final transient AvroCoder<AggregatedActivePowerRecord> avroEnCoder =
AvroCoder.of(AggregatedActivePowerRecord.class);
@Override
public AggregatedActivePowerRecord deserialize(final String topic, final byte[] data) {
AggregatedActivePowerRecord value = null;
try {
value = this.avroEnCoder.decode(new ByteArrayInputStream(data));
} catch (final IOException e) {
LOGGER.error("Could not deserialize AggregatedActivePowerRecord", e);
}
return value;
}
} }
package serialization; package serialization;
import java.io.ByteArrayOutputStream; import io.confluent.kafka.streams.serdes.avro.SpecificAvroSerializer;
import java.io.IOException;
import org.apache.beam.sdk.coders.AvroCoder;
import org.apache.kafka.common.serialization.Serializer; import org.apache.kafka.common.serialization.Serializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import titan.ccp.model.records.AggregatedActivePowerRecord; import titan.ccp.model.records.AggregatedActivePowerRecord;
/** /**
* Wrapper Class that encapsulates a IMonitoringRecordSerde.serializer in a Serializer * {@link Serializer} for an {@link AggregatedActivePowerRecord}.
*/ */
public class AggregatedActivePowerRecordSerializer public class AggregatedActivePowerRecordSerializer
implements Serializer<AggregatedActivePowerRecord> { extends SpecificAvroSerializer<AggregatedActivePowerRecord> {
private static final Logger LOGGER =
LoggerFactory.getLogger(AggregatedActivePowerRecordSerializer.class);
private final transient AvroCoder<AggregatedActivePowerRecord> avroEnCoder =
AvroCoder.of(AggregatedActivePowerRecord.class);
@Override
public byte[] serialize(final String topic, final AggregatedActivePowerRecord data) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
this.avroEnCoder.encode(data, out);
} catch (final IOException e) {
LOGGER.error("Could not serialize AggregatedActivePowerRecord", e);
}
final byte[] result = out.toByteArray();
try {
out.close();
} catch (final IOException e) {
LOGGER.error(
"Could not close output stream after serialization of AggregatedActivePowerRecord", e);
}
return result;
}
@Override
public void close() {
Serializer.super.close();
}
} }
...@@ -61,7 +61,7 @@ cleanup_settings_version=2 ...@@ -61,7 +61,7 @@ cleanup_settings_version=2
eclipse.preferences.version=1 eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_CAU-SE-Style formatter_profile=_CAU-SE-Style
formatter_settings_version=15 formatter_settings_version=21
org.eclipse.jdt.ui.ignorelowercasenames=true org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=; org.eclipse.jdt.ui.importorder=;
org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.ondemandthreshold=99
......
...@@ -61,7 +61,7 @@ cleanup_settings_version=2 ...@@ -61,7 +61,7 @@ cleanup_settings_version=2
eclipse.preferences.version=1 eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_CAU-SE-Style formatter_profile=_CAU-SE-Style
formatter_settings_version=15 formatter_settings_version=21
org.eclipse.jdt.ui.ignorelowercasenames=true org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=; org.eclipse.jdt.ui.importorder=;
org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.ondemandthreshold=99
......
...@@ -61,7 +61,7 @@ cleanup_settings_version=2 ...@@ -61,7 +61,7 @@ cleanup_settings_version=2
eclipse.preferences.version=1 eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_CAU-SE-Style formatter_profile=_CAU-SE-Style
formatter_settings_version=15 formatter_settings_version=21
org.eclipse.jdt.ui.ignorelowercasenames=true org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=; org.eclipse.jdt.ui.importorder=;
org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.ondemandthreshold=99
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment