Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#2462): Use unique stream identifier for functions #2463

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.streampipes.extensions.management.util.GroundingDebugUtils;
import org.apache.streampipes.model.SpDataStream;
import org.apache.streampipes.model.constants.PropertySelectorConstants;
import org.apache.streampipes.model.function.FunctionId;
import org.apache.streampipes.model.monitoring.SpLogEntry;
import org.apache.streampipes.model.monitoring.SpLogMessage;
import org.apache.streampipes.model.runtime.Event;
Expand Down Expand Up @@ -67,7 +68,7 @@ public StreamPipesFunction() {
public void invokeRuntime(String serviceGroup) {
var functionId = this.getFunctionConfig().getFunctionId();

this.initializeProducers();
this.initializeProducers(functionId);

var context = new FunctionContextGenerator(
functionId.getId(),
Expand All @@ -88,7 +89,7 @@ public void invokeRuntime(String serviceGroup) {
index.getAndIncrement();
});

this.inputCollectors = getInputCollectors(context.getStreams());
this.inputCollectors = getInputCollectors(functionId, context.getStreams());

LOG.info("Invoking function {}:{}", functionId.getId(), functionId.getVersion());

Expand Down Expand Up @@ -139,37 +140,45 @@ private void addError(RuntimeException e) {
SpLogEntry.from(System.currentTimeMillis(), SpLogMessage.from(e)));
}

private void initializeProducers() {
this.outputCollectors = this.getOutputCollectors();
private void initializeProducers(FunctionId functionId) {
this.outputCollectors = this.getOutputCollectors(functionId);
this.outputCollectors.forEach((key, value) -> value.connect());
}

private Map<String, SpOutputCollector> getOutputCollectors() {
private Map<String, SpOutputCollector> getOutputCollectors(FunctionId functionId) {
this.getFunctionConfig().getOutputDataStreams().forEach((key, value) -> {
var uniqueStreamId = getUniqueStreamId(functionId, value);
this.outputCollectors.put(
key,
uniqueStreamId,
ProtocolManager.makeOutputCollector(
value.getEventGrounding().getTransportProtocol(),
value.getEventGrounding().getTransportFormats().get(0),
key));
uniqueStreamId));
});

return this.outputCollectors;
}

private Map<String, SpInputCollector> getInputCollectors(Collection<SpDataStream> streams) throws SpRuntimeException {
private Map<String, SpInputCollector> getInputCollectors(FunctionId functionId,
Collection<SpDataStream> streams) throws SpRuntimeException {
Map<String, SpInputCollector> inputCollectors = new HashMap<>();
var env = getEnvironment();
for (SpDataStream is : streams) {
var uniqueStreamId = getUniqueStreamId(functionId, is);
if (env.getSpDebug().getValueOrDefault()) {
GroundingDebugUtils.modifyGrounding(is.getEventGrounding());
}
inputCollectors.put(is.getElementId(), ProtocolManager.findInputCollector(is.getEventGrounding()
inputCollectors.put(uniqueStreamId, ProtocolManager.findInputCollector(is.getEventGrounding()
.getTransportProtocol(), is.getEventGrounding().getTransportFormats().get(0), false));
}
return inputCollectors;
}

private String getUniqueStreamId(FunctionId functionId,
SpDataStream dataStream) {
return String.join("-", functionId.getId(), dataStream.getElementId());
}

private void registerConsumers() {
this.inputCollectors.forEach((key, is) -> {
is.registerConsumer(key, this);
Expand Down
Loading