use of com.hortonworks.streamline.streams.catalog.TopologyProcessor in project streamline by hortonworks.
the class StreamCatalogService method getTopologyProcessor.
public TopologyProcessor getTopologyProcessor(Long topologyId, Long processorId, Long versionId) {
TopologyProcessor topologyProcessor = new TopologyProcessor();
topologyProcessor.setId(processorId);
topologyProcessor.setVersionId(versionId);
TopologyProcessor processor = dao.get(new StorableKey(TOPOLOGY_PROCESSOR_NAMESPACE, topologyProcessor.getPrimaryKey()));
if (processor == null || !processor.getTopologyId().equals(topologyId)) {
return null;
}
fillProcessorStreams(processor);
processor.setVersionTimestamp(getVersionTimestamp(versionId));
return processor;
}
use of com.hortonworks.streamline.streams.catalog.TopologyProcessor in project streamline by hortonworks.
the class StreamCatalogService method setReconfigureRules.
private void setReconfigureRules(List<TopologyProcessor> processors, List<TopologyStream> affectedStreams) {
Map<Long, BiFunction<TopologyProcessor, Long, BaseTopologyRule>> bundles = new HashMap<>();
TopologyComponentBundle bundle = getCurrentTopologyComponentBundle(TopologyComponentBundle.TopologyComponentType.PROCESSOR, ComponentTypes.RULE);
bundles.put(bundle.getId(), (p, r) -> getRule(p.getTopologyId(), r, p.getVersionId()));
bundle = getCurrentTopologyComponentBundle(TopologyComponentBundle.TopologyComponentType.PROCESSOR, ComponentTypes.BRANCH);
bundles.put(bundle.getId(), (p, r) -> getBranchRule(p.getTopologyId(), r, p.getVersionId()));
bundle = getCurrentTopologyComponentBundle(TopologyComponentBundle.TopologyComponentType.PROCESSOR, ComponentTypes.PROJECTION);
bundles.put(bundle.getId(), (p, r) -> getRule(p.getTopologyId(), r, p.getVersionId()));
bundle = getCurrentTopologyComponentBundle(TopologyComponentBundle.TopologyComponentType.PROCESSOR, ComponentTypes.WINDOW);
bundles.put(bundle.getId(), (p, r) -> getWindow(p.getTopologyId(), r, p.getVersionId()));
Set<String> affectedStreamIds = affectedStreams.stream().map(TopologyStream::getStreamId).collect(Collectors.toSet());
for (TopologyProcessor processor : processors) {
BiFunction<TopologyProcessor, Long, BaseTopologyRule> function;
if ((function = bundles.get(processor.getTopologyComponentBundleId())) != null) {
Optional<Object> ruleList = processor.getConfig().getAnyOptional(RulesProcessor.CONFIG_KEY_RULES);
if (ruleList.isPresent()) {
ObjectMapper objectMapper = new ObjectMapper();
List<Long> ruleIds = objectMapper.convertValue(ruleList.get(), new TypeReference<List<Long>>() {
});
for (Long ruleId : ruleIds) {
BaseTopologyRule rule = function.apply(processor, ruleId);
if (rule != null) {
for (String stream : rule.getInputStreams()) {
if (affectedStreamIds.contains(stream)) {
rule.setReconfigure(true);
dao.addOrUpdate(rule);
break;
}
}
}
}
}
}
}
}
use of com.hortonworks.streamline.streams.catalog.TopologyProcessor in project streamline by hortonworks.
the class StreamCatalogService method removeTopologyProcessor.
public TopologyProcessor removeTopologyProcessor(Long topologyId, Long processorId, Long versionId, boolean removeEdges) {
TopologyProcessor topologyProcessor = getTopologyProcessor(topologyId, processorId, versionId);
if (topologyProcessor != null) {
if (removeEdges) {
removeAllEdges(topologyProcessor);
}
removeProcessorStreamMapping(topologyProcessor);
topologyProcessor = dao.<TopologyProcessor>remove(new StorableKey(TOPOLOGY_PROCESSOR_NAMESPACE, topologyProcessor.getPrimaryKey()));
topologyProcessor.setVersionTimestamp(updateVersionTimestamp(versionId).getTimestamp());
}
return topologyProcessor;
}
use of com.hortonworks.streamline.streams.catalog.TopologyProcessor in project streamline by hortonworks.
the class StreamCatalogService method removeCustomProcessorInfoAsBundle.
public CustomProcessorInfo removeCustomProcessorInfoAsBundle(String name) throws IOException {
List<QueryParam> queryParams = new ArrayList<>();
queryParams.add(new QueryParam(CustomProcessorInfo.NAME, name));
Collection<TopologyComponentBundle> result = this.listCustomProcessorBundlesWithFilter(queryParams);
if (result.isEmpty() || result.size() != 1) {
throw new IOException("Failed to delete custom processor with name:" + name);
}
TopologyComponentBundle customProcessorBundle = result.iterator().next();
Collection<TopologyProcessor> processors = this.listTopologyProcessors();
if (processors != null && !processors.isEmpty()) {
for (TopologyProcessor topologyProcessor : processors) {
if (topologyProcessor.getTopologyComponentBundleId().equals(customProcessorBundle.getId())) {
throw new IOException("Cannot delete custom processor as it is being used in one of the topologies.");
}
}
}
this.removeTopologyComponentBundle(customProcessorBundle.getId());
return CustomProcessorInfo.fromTopologyComponentBundle(customProcessorBundle);
}
use of com.hortonworks.streamline.streams.catalog.TopologyProcessor in project streamline by hortonworks.
the class StreamCatalogService method addOrUpdateTopologyProcessor.
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;
}
Aggregations