Search in sources :

Example 16 with TopologyProcessor

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;
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) TopologyProcessor(com.hortonworks.streamline.streams.catalog.TopologyProcessor)

Example 17 with TopologyProcessor

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;
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : BaseTopologyRule(com.hortonworks.streamline.streams.catalog.BaseTopologyRule) HashMap(java.util.HashMap) BiFunction(java.util.function.BiFunction) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) TopologyProcessor(com.hortonworks.streamline.streams.catalog.TopologyProcessor) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)

Example 18 with TopologyProcessor

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;
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) TopologyProcessor(com.hortonworks.streamline.streams.catalog.TopologyProcessor)

Example 19 with 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);
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) WSUtils.versionIdQueryParam(com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam) WSUtils.buildEdgesFromQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam) WSUtils.currentVersionQueryParam(com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam) WSUtils.buildEdgesToQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TopologyProcessor(com.hortonworks.streamline.streams.catalog.TopologyProcessor) TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)

Example 20 with TopologyProcessor

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;
}
Also used : Sets(com.google.common.collect.Sets) TopologyProcessor(com.hortonworks.streamline.streams.catalog.TopologyProcessor)

Aggregations

TopologyProcessor (com.hortonworks.streamline.streams.catalog.TopologyProcessor)21 TopologySink (com.hortonworks.streamline.streams.catalog.TopologySink)6 Timed (com.codahale.metrics.annotation.Timed)5 QueryParam (com.hortonworks.registries.common.QueryParam)5 WSUtils.buildEdgesFromQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam)5 WSUtils.buildEdgesToQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam)5 WSUtils.currentVersionQueryParam (com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam)5 WSUtils.versionIdQueryParam (com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam)5 BaseTopologyRule (com.hortonworks.streamline.streams.catalog.BaseTopologyRule)5 TopologySource (com.hortonworks.streamline.streams.catalog.TopologySource)5 TopologyComponentBundle (com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)5 StorableKey (com.hortonworks.registries.storage.StorableKey)4 TopologyBranchRule (com.hortonworks.streamline.streams.catalog.TopologyBranchRule)4 TopologyRule (com.hortonworks.streamline.streams.catalog.TopologyRule)4 TopologyStream (com.hortonworks.streamline.streams.catalog.TopologyStream)4 Path (javax.ws.rs.Path)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ImmutableList (com.google.common.collect.ImmutableList)3 Sets (com.google.common.collect.Sets)3 TopologyEdge (com.hortonworks.streamline.streams.catalog.TopologyEdge)3