public TopologyProcessor addOrUpdateTopologyProcessor(Long topologyId, Long id, TopologyProcessor topologyProcessor) {
Long currentTopologyVersionId = getCurrentVersionId(topologyId);
topologyProcessor.setId(id);
topologyProcessor.setVersionId(currentTopologyVersionId);
topologyProcessor.setTopologyId(topologyId);
validateTopologyProcessor(topologyProcessor);
topologyProcessor.setReconfigure(false);
dao.addOrUpdate(topologyProcessor);
List<Long> newList = Collections.emptyList();
if (topologyProcessor.getOutputStreamIds() != null) {
newList = topologyProcessor.getOutputStreamIds();
} else if (topologyProcessor.getOutputStreams() != null) {
newList = updateOutputStreams(topologyProcessor);
}
List<Long> existing = getOutputStreamIds(topologyProcessor);
Sets.SetView<Long> streamIdsToRemove = Sets.difference(ImmutableSet.copyOf(existing), ImmutableSet.copyOf(newList));
Sets.SetView<Long> streamIdsToAdd = Sets.difference(ImmutableSet.copyOf(newList), ImmutableSet.copyOf(existing));
removeProcessorStreamMapping(topologyProcessor, Lists.newArrayList(streamIdsToRemove));
addProcessorStreamMapping(topologyProcessor, Lists.newArrayList(streamIdsToAdd));
TopologyProcessor updatedProcessor = getTopologyProcessor(topologyId, id, currentTopologyVersionId);
updatedProcessor.setVersionTimestamp(updateVersionTimestamp(currentTopologyVersionId).getTimestamp());
return topologyProcessor;
}