use of com.hortonworks.streamline.streams.catalog.TopologySink in project streamline by hortonworks.
the class TopologyComponentFactory method getInputComponent.
private InputComponent getInputComponent(TopologyEdge topologyEdge) {
TopologySink topologySink;
TopologyProcessor topologyProcessor;
if ((topologySink = catalogService.getTopologySink(topologyEdge.getTopologyId(), topologyEdge.getToId(), topologyEdge.getVersionId())) != null) {
return getStreamlineSink(topologySink);
} else if ((topologyProcessor = catalogService.getTopologyProcessor(topologyEdge.getTopologyId(), topologyEdge.getToId(), topologyEdge.getVersionId())) != null) {
return getStreamlineProcessor(topologyProcessor);
} else {
throw new IllegalArgumentException("Invalid to id for edge " + topologyEdge);
}
}
use of com.hortonworks.streamline.streams.catalog.TopologySink in project streamline by hortonworks.
the class TopologyExportVisitor method visit.
public void visit(StreamlineSink sink) {
TopologySink topologySink = streamCatalogService.getTopologySink(topologyId, Long.parseLong(sink.getId()));
topologyData.addSink(topologySink);
storeBundleIdToType(sink);
}
use of com.hortonworks.streamline.streams.catalog.TopologySink in project streamline by hortonworks.
the class StreamCatalogService method getTo.
private TopologyComponent getTo(TopologyEdge edge) {
TopologyProcessor processor = getTopologyProcessor(edge.getTopologyId(), edge.getToId(), edge.getVersionId());
TopologySink sink = getTopologySink(edge.getTopologyId(), edge.getToId(), edge.getVersionId());
return processor != null ? processor : sink;
}
use of com.hortonworks.streamline.streams.catalog.TopologySink in project streamline by hortonworks.
the class StreamCatalogService method doImportTopology.
private Topology doImportTopology(Topology newTopology, TopologyData topologyData) throws Exception {
List<TopologySource> topologySources = topologyData.getSources();
Map<Long, Long> oldToNewComponentIds = new HashMap<>();
Map<Long, Long> oldToNewRuleIds = new HashMap<>();
Map<Long, Long> oldToNewWindowIds = new HashMap<>();
Map<Long, Long> oldToNewBranchRuleIds = new HashMap<>();
Map<Long, Long> oldToNewStreamIds = new HashMap<>();
// import source streams
for (TopologySource topologySource : topologySources) {
topologySource.setOutputStreamIds(importOutputStreams(newTopology.getId(), oldToNewStreamIds, topologySource.getOutputStreams()));
topologySource.setOutputStreams(null);
}
// import processor streams
for (TopologyProcessor topologyProcessor : topologyData.getProcessors()) {
topologyProcessor.setOutputStreamIds(importOutputStreams(newTopology.getId(), oldToNewStreamIds, topologyProcessor.getOutputStreams()));
topologyProcessor.setOutputStreams(null);
}
// import rules
for (TopologyRule rule : topologyData.getRules()) {
Long currentId = rule.getId();
rule.setId(null);
TopologyRule addedRule = addRule(newTopology.getId(), rule);
oldToNewRuleIds.put(currentId, addedRule.getId());
}
// import windowed rules
for (TopologyWindow window : topologyData.getWindows()) {
Long currentId = window.getId();
window.setId(null);
TopologyWindow addedWindow = addWindow(newTopology.getId(), window);
oldToNewWindowIds.put(currentId, addedWindow.getId());
}
// import branch rules
for (TopologyBranchRule branchRule : topologyData.getBranchRules()) {
Long currentId = branchRule.getId();
branchRule.setId(null);
TopologyBranchRule addedBranchRule = addBranchRule(newTopology.getId(), branchRule);
oldToNewBranchRuleIds.put(currentId, addedBranchRule.getId());
}
// import sources
for (TopologySource topologySource : topologySources) {
Long oldComponentId = topologySource.getId();
topologySource.setId(null);
topologySource.setTopologyId(newTopology.getId());
TopologyComponentBundle bundle = getCurrentTopologyComponentBundle(TopologyComponentBundle.TopologyComponentType.SOURCE, topologyData.getBundleIdToType().get(topologySource.getTopologyComponentBundleId().toString()));
topologySource.setTopologyComponentBundleId(bundle.getId());
addTopologySource(newTopology.getId(), topologySource);
oldToNewComponentIds.put(oldComponentId, topologySource.getId());
}
// import processors
for (TopologyProcessor topologyProcessor : topologyData.getProcessors()) {
Long oldComponentId = topologyProcessor.getId();
topologyProcessor.setId(null);
topologyProcessor.setTopologyId(newTopology.getId());
TopologyComponentBundle bundle;
String subType = topologyData.getBundleIdToType().get(topologyProcessor.getTopologyComponentBundleId().toString());
if (TopologyLayoutConstants.JSON_KEY_CUSTOM_PROCESSOR_SUB_TYPE.equals(subType)) {
QueryParam queryParam = new QueryParam(CustomProcessorInfo.NAME, topologyProcessor.getConfig().get(CustomProcessorInfo.NAME));
Collection<TopologyComponentBundle> result = listCustomProcessorBundlesWithFilter(Collections.singletonList(queryParam));
if (result.size() != 1) {
throw new IllegalStateException("Not able to find topology component bundle for custom processor :" + topologyProcessor.getConfig().get(CustomProcessorInfo.NAME));
}
bundle = result.iterator().next();
} else {
bundle = getCurrentTopologyComponentBundle(TopologyComponentBundle.TopologyComponentType.PROCESSOR, subType);
}
topologyProcessor.setTopologyComponentBundleId(bundle.getId());
Optional<Object> ruleListObj = topologyProcessor.getConfig().getAnyOptional(RulesProcessor.CONFIG_KEY_RULES);
ruleListObj.ifPresent(ruleList -> {
List<Long> ruleIds = new ObjectMapper().convertValue(ruleList, new TypeReference<List<Long>>() {
});
List<Long> updatedRuleIds = new ArrayList<>();
if (ComponentTypes.RULE.equals(bundle.getSubType()) || ComponentTypes.PROJECTION.equals(bundle.getSubType())) {
ruleIds.forEach(ruleId -> updatedRuleIds.add(oldToNewRuleIds.get(ruleId)));
} else if (bundle.getSubType().equals(ComponentTypes.BRANCH)) {
ruleIds.forEach(ruleId -> updatedRuleIds.add(oldToNewBranchRuleIds.get(ruleId)));
} else if (bundle.getSubType().equals(ComponentTypes.WINDOW)) {
ruleIds.forEach(ruleId -> updatedRuleIds.add(oldToNewWindowIds.get(ruleId)));
}
topologyProcessor.getConfig().setAny(RulesProcessor.CONFIG_KEY_RULES, updatedRuleIds);
});
addTopologyProcessor(newTopology.getId(), topologyProcessor);
oldToNewComponentIds.put(oldComponentId, topologyProcessor.getId());
}
// import sinks
for (TopologySink topologySink : topologyData.getSinks()) {
topologySink.setTopologyId(newTopology.getId());
Long currentId = topologySink.getId();
topologySink.setId(null);
TopologyComponentBundle bundle = getCurrentTopologyComponentBundle(TopologyComponentBundle.TopologyComponentType.SINK, topologyData.getBundleIdToType().get(topologySink.getTopologyComponentBundleId().toString()));
topologySink.setTopologyComponentBundleId(bundle.getId());
if (bundle.getSubType().equals(NOTIFICATION)) {
updateNotifierJarFileName(topologySink);
}
addTopologySink(newTopology.getId(), topologySink);
oldToNewComponentIds.put(currentId, topologySink.getId());
}
// import edges
for (TopologyEdge topologyEdge : topologyData.getEdges()) {
List<StreamGrouping> streamGroupings = topologyEdge.getStreamGroupings();
for (StreamGrouping streamGrouping : streamGroupings) {
Long newStreamId = oldToNewStreamIds.get(streamGrouping.getStreamId());
streamGrouping.setStreamId(newStreamId);
}
topologyEdge.setId(null);
topologyEdge.setTopologyId(newTopology.getId());
topologyEdge.setFromId(oldToNewComponentIds.get(topologyEdge.getFromId()));
topologyEdge.setToId(oldToNewComponentIds.get(topologyEdge.getToId()));
addTopologyEdge(newTopology.getId(), topologyEdge);
}
// import topology editor metadata
TopologyEditorMetadata topologyEditorMetadata = topologyData.getTopologyEditorMetadata();
topologyEditorMetadata.setTopologyId(newTopology.getId());
if (topologyEditorMetadata.getData() != null) {
TopologyUIData topologyUIData = new ObjectMapper().readValue(topologyEditorMetadata.getData(), TopologyUIData.class);
topologyUIData.getSources().forEach(c -> c.setId(oldToNewComponentIds.get(c.getId())));
topologyUIData.getProcessors().forEach(c -> c.setId(oldToNewComponentIds.get(c.getId())));
topologyUIData.getSinks().forEach(c -> c.setId(oldToNewComponentIds.get(c.getId())));
topologyEditorMetadata.setData(new ObjectMapper().writeValueAsString(topologyUIData));
} else {
topologyEditorMetadata.setData(StringUtils.EMPTY);
}
addTopologyEditorMetadata(newTopology.getId(), topologyData.getTopologyEditorMetadata());
return newTopology;
}
use of com.hortonworks.streamline.streams.catalog.TopologySink in project streamline by hortonworks.
the class StreamCatalogService method removeTopologySink.
public TopologySink removeTopologySink(Long topologyId, Long sinkId, Long versionId, boolean removeEdges) {
TopologySink topologySink = getTopologySink(topologyId, sinkId, versionId);
if (topologySink != null) {
if (removeEdges) {
removeAllEdges(topologySink);
}
removeAllTopologyTestSinks(topologySink);
topologySink = dao.<TopologySink>remove(new StorableKey(TOPOLOGY_SINK_NAMESPACE, topologySink.getPrimaryKey()));
topologySink.setVersionTimestamp(updateVersionTimestamp(versionId).getTimestamp());
}
return topologySink;
}
Aggregations