Search in sources :

Example 1 with TopologyComponent

use of com.hortonworks.streamline.streams.catalog.TopologyComponent in project streamline by hortonworks.

the class MetricsResource method getCompleteLatency.

@GET
@Path("/topologies/{id}/components/{topologyComponentId}/complete_latency")
@Timed
public Response getCompleteLatency(@PathParam("id") Long id, @PathParam("topologyComponentId") Long topologyComponentId, @QueryParam("from") Long from, @QueryParam("to") Long to, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, id, READ);
    assertTimeRange(from, to);
    Topology topology = catalogService.getTopology(id);
    TopologyComponent topologyComponent = catalogService.getTopologyComponent(id, topologyComponentId);
    if (topology != null && topologyComponent != null) {
        String asUser = WSUtils.getUserFromSecurityContext(securityContext);
        Map<Long, Double> metrics = metricsService.getCompleteLatency(topology, topologyComponent, from, to, asUser);
        return WSUtils.respondEntity(metrics, OK);
    } else if (topology == null) {
        throw EntityNotFoundException.byId("Topology: " + id.toString());
    } else {
        // topologyComponent == null
        throw EntityNotFoundException.byId("TopologyComponent: " + id.toString());
    }
}
Also used : TopologyComponent(com.hortonworks.streamline.streams.catalog.TopologyComponent) Topology(com.hortonworks.streamline.streams.catalog.Topology) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 2 with TopologyComponent

use of com.hortonworks.streamline.streams.catalog.TopologyComponent in project streamline by hortonworks.

the class MetricsResource method getKafkaTopicOffsets.

@GET
@Path("/topologies/{id}/components/{topologyComponentId}/kafka_topic_offsets")
@Timed
public Response getKafkaTopicOffsets(@PathParam("id") Long id, @PathParam("topologyComponentId") Long topologyComponentId, @QueryParam("from") Long from, @QueryParam("to") Long to, @Context SecurityContext securityContext) throws IOException {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, id, READ);
    assertTimeRange(from, to);
    Topology topology = catalogService.getTopology(id);
    TopologyComponent topologyComponent = catalogService.getTopologyComponent(id, topologyComponentId);
    if (topology != null && topologyComponent != null) {
        String asUser = WSUtils.getUserFromSecurityContext(securityContext);
        Map<String, Map<Long, Double>> metrics = metricsService.getKafkaTopicOffsets(topology, topologyComponent, from, to, asUser);
        return WSUtils.respondEntity(metrics, OK);
    } else if (topology == null) {
        throw EntityNotFoundException.byId("Topology: " + id.toString());
    } else {
        // topologyComponent == null
        throw EntityNotFoundException.byId("TopologyComponent: " + id.toString());
    }
}
Also used : TopologyComponent(com.hortonworks.streamline.streams.catalog.TopologyComponent) Topology(com.hortonworks.streamline.streams.catalog.Topology) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 3 with TopologyComponent

use of com.hortonworks.streamline.streams.catalog.TopologyComponent in project streamline by hortonworks.

the class MetricsResource method getComponentStats.

@GET
@Path("/topologies/{id}/components/all/component_stats")
@Timed
public Response getComponentStats(@PathParam("id") Long id, @QueryParam("from") Long from, @QueryParam("to") Long to, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, id, READ);
    assertTimeRange(from, to);
    Topology topology = catalogService.getTopology(id);
    if (topology != null) {
        List<TopologyComponent> topologyComponents = new ArrayList<>();
        List<com.hortonworks.registries.common.QueryParam> queryParams = new ArrayList<>();
        queryParams.add(new com.hortonworks.registries.common.QueryParam("topologyId", String.valueOf(topology.getId())));
        queryParams.add(new com.hortonworks.registries.common.QueryParam("versionId", String.valueOf(topology.getVersionId())));
        topologyComponents.addAll(catalogService.listTopologySources(queryParams));
        topologyComponents.addAll(catalogService.listTopologyProcessors(queryParams));
        topologyComponents.addAll(catalogService.listTopologySinks(queryParams));
        Map<String, TopologyTimeSeriesMetrics.TimeSeriesComponentMetric> topologyMetrics = ParallelStreamUtil.execute(() -> topologyComponents.parallelStream().map(c -> {
            try {
                String asUser = WSUtils.getUserFromSecurityContext(securityContext);
                return Pair.of(c, metricsService.getComponentStats(topology, c, from, to, asUser));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }).collect(toMap(m -> m.getKey().getId().toString(), m -> m.getValue())), forkJoinPool);
        return WSUtils.respondEntity(topologyMetrics, OK);
    }
    throw EntityNotFoundException.byId(id.toString());
}
Also used : TopologyComponent(com.hortonworks.streamline.streams.catalog.TopologyComponent) ArrayList(java.util.ArrayList) Topology(com.hortonworks.streamline.streams.catalog.Topology) IOException(java.io.IOException) QueryParam(javax.ws.rs.QueryParam) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 4 with TopologyComponent

use of com.hortonworks.streamline.streams.catalog.TopologyComponent in project streamline by hortonworks.

the class StreamCatalogService method setReconfigureTarget.

private void setReconfigureTarget(TopologyEdge edge, TopologyStream stream) {
    TopologyComponent component = getTo(edge);
    component.setReconfigure(true);
    dao.addOrUpdate(component);
    // if component is a processor, update any rules in that processor that uses any of the streams
    if (component instanceof TopologyProcessor) {
        setReconfigureRules(Collections.singletonList((TopologyProcessor) component), edge.getStreamGroupings().stream().map(StreamGrouping::getStreamId).map(sid -> getStreamInfo(edge.getTopologyId(), sid, edge.getVersionId())).filter(curStream -> stream == null || curStream.getId().equals(stream.getId())).collect(Collectors.toList()));
    }
}
Also used : TopologyComponent(com.hortonworks.streamline.streams.catalog.TopologyComponent) Topology(com.hortonworks.streamline.streams.catalog.Topology) TopologyProcessorStreamMap(com.hortonworks.streamline.streams.catalog.TopologyProcessorStreamMap) Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) MLModelRegistryClient(com.hortonworks.streamline.registries.model.client.MLModelRegistryClient) UDAF(com.hortonworks.streamline.streams.rule.UDAF) Notifier(com.hortonworks.streamline.streams.catalog.Notifier) StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) Utils(com.hortonworks.streamline.common.util.Utils) QueryParam(com.hortonworks.registries.common.QueryParam) FileStorage(com.hortonworks.registries.common.util.FileStorage) UDAF2(com.hortonworks.streamline.streams.rule.UDAF2) Collections2(com.google.common.collect.Collections2) ComponentUISpecification(com.hortonworks.streamline.common.ComponentUISpecification) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) StreamGrouping(com.hortonworks.streamline.streams.catalog.TopologyEdge.StreamGrouping) ComponentConfigException(com.hortonworks.streamline.common.exception.ComponentConfigException) Matcher(java.util.regex.Matcher) TopologyEditorMetadata(com.hortonworks.streamline.streams.catalog.TopologyEditorMetadata) Map(java.util.Map) RuleParser(com.hortonworks.streamline.streams.catalog.rule.RuleParser) TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle) WSUtils.versionIdQueryParam(com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam) TopologyData(com.hortonworks.streamline.streams.catalog.topology.TopologyData) Set(java.util.Set) NOTIFICATION(com.hortonworks.streamline.common.ComponentTypes.NOTIFICATION) CURRENT_VERSION(com.hortonworks.streamline.common.util.WSUtils.CURRENT_VERSION) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CustomProcessorInfo(com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo) StorableKey(com.hortonworks.registries.storage.StorableKey) TopologyProcessor(com.hortonworks.streamline.streams.catalog.TopologyProcessor) Joiner(com.google.common.base.Joiner) TopologyState(com.hortonworks.streamline.streams.catalog.topology.state.TopologyState) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) TopologySourceStreamMap(com.hortonworks.streamline.streams.catalog.TopologySourceStreamMap) Projection(com.hortonworks.streamline.streams.catalog.Projection) TopologyOutputComponent(com.hortonworks.streamline.streams.catalog.TopologyOutputComponent) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) Nullable(javax.annotation.Nullable) TopologyVersion(com.hortonworks.streamline.streams.catalog.TopologyVersion) UDF(com.hortonworks.streamline.streams.catalog.UDF) IOException(java.io.IOException) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) TopologyWindow(com.hortonworks.streamline.streams.catalog.TopologyWindow) TreeMap(java.util.TreeMap) File(com.hortonworks.streamline.streams.catalog.File) DigestInputStream(java.security.DigestInputStream) Preconditions(com.google.common.base.Preconditions) TopologyDagBuilder(com.hortonworks.streamline.streams.catalog.topology.component.TopologyDagBuilder) BiFunction(java.util.function.BiFunction) UDF4(com.hortonworks.streamline.streams.rule.UDF4) LoggerFactory(org.slf4j.LoggerFactory) UDF3(com.hortonworks.streamline.streams.rule.UDF3) UDF2(com.hortonworks.streamline.streams.rule.UDF2) UDF7(com.hortonworks.streamline.streams.rule.UDF7) UDF6(com.hortonworks.streamline.streams.rule.UDF6) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) UDF5(com.hortonworks.streamline.streams.rule.UDF5) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) BaseTopologyRule(com.hortonworks.streamline.streams.catalog.BaseTopologyRule) TopologyEdge(com.hortonworks.streamline.streams.catalog.TopologyEdge) WSUtils(com.hortonworks.streamline.common.util.WSUtils) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) StorageUtils(com.hortonworks.registries.storage.util.StorageUtils) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) TopologySink(com.hortonworks.streamline.streams.catalog.TopologySink) FileUtil(com.hortonworks.streamline.common.util.FileUtil) Collection(java.util.Collection) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) TopologySource(com.hortonworks.streamline.streams.catalog.TopologySource) List(java.util.List) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) StorageManager(com.hortonworks.registries.storage.StorageManager) TopologyTestRunCaseSink(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) WSUtils.buildEdgesFromQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam) TopologyLayoutConstants(com.hortonworks.streamline.streams.layout.TopologyLayoutConstants) MessageDigest(java.security.MessageDigest) TopologyUIData(com.hortonworks.streamline.streams.catalog.TopologyEditorMetadata.TopologyUIData) TopologyEditorToolbar(com.hortonworks.streamline.streams.catalog.TopologyEditorToolbar) HashMap(java.util.HashMap) Hex(org.apache.commons.codec.binary.Hex) ComponentTypes(com.hortonworks.streamline.common.ComponentTypes) Schema(com.hortonworks.registries.common.Schema) HashSet(java.util.HashSet) WSUtils.currentVersionQueryParam(com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam) ImmutableList(com.google.common.collect.ImmutableList) CustomProcessorRuntime(com.hortonworks.streamline.streams.runtime.CustomProcessorRuntime) WSUtils.buildEdgesToQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam) TopologyExportVisitor(com.hortonworks.streamline.streams.catalog.topology.component.TopologyExportVisitor) Logger(org.slf4j.Logger) Stream(com.hortonworks.streamline.streams.layout.component.Stream) ProxyUtil(com.hortonworks.streamline.common.util.ProxyUtil) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) FileInputStream(java.io.FileInputStream) StorageException(com.hortonworks.registries.storage.exception.StorageException) TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) TopologyComponent(com.hortonworks.streamline.streams.catalog.TopologyComponent) FluxComponent(com.hortonworks.streamline.streams.layout.storm.FluxComponent) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) InputStream(java.io.InputStream) TopologyProcessor(com.hortonworks.streamline.streams.catalog.TopologyProcessor) StreamGrouping(com.hortonworks.streamline.streams.catalog.TopologyEdge.StreamGrouping)

Example 5 with TopologyComponent

use of com.hortonworks.streamline.streams.catalog.TopologyComponent in project streamline by hortonworks.

the class StreamCatalogService method validateEdge.

// validate from, to and stream ids of the edge
private void validateEdge(TopologyEdge edge) {
    TopologyOutputComponent from = getFrom(edge);
    if ((from == null || !from.getTopologyId().equals(edge.getTopologyId()))) {
        throw new IllegalArgumentException("Invalid source for edge " + edge);
    }
    TopologyComponent to = getTo(edge);
    if ((to == null || !to.getTopologyId().equals(edge.getTopologyId()))) {
        throw new IllegalArgumentException("Invalid destination for edge " + edge);
    }
    Set<Long> outputStreamIds = new HashSet<>();
    if (from.getOutputStreamIds() != null) {
        outputStreamIds.addAll(from.getOutputStreamIds());
    } else if (from.getOutputStreams() != null) {
        outputStreamIds.addAll(Collections2.transform(from.getOutputStreams(), new Function<TopologyStream, Long>() {

            @Override
            public Long apply(TopologyStream input) {
                return input.getId();
            }
        }));
    }
    Collection<Long> edgeStreamIds = Collections2.transform(edge.getStreamGroupings(), new Function<StreamGrouping, Long>() {

        public Long apply(StreamGrouping streamGrouping) {
            return streamGrouping.getStreamId();
        }
    });
    if (!outputStreamIds.containsAll(edgeStreamIds)) {
        throw new IllegalArgumentException("Edge stream Ids " + edgeStreamIds + " must be a subset of outputStreamIds " + outputStreamIds);
    }
    // check the fields specified in the fields grouping is a subset of the stream fields
    for (StreamGrouping streamGrouping : edge.getStreamGroupings()) {
        List<String> fields;
        if ((fields = streamGrouping.getFields()) != null) {
            Set<String> schemaFieldPatterns = getFieldPatterns(getStreamInfo(edge.getTopologyId(), streamGrouping.getStreamId(), edge.getVersionId()).getFields());
            fields.forEach(field -> {
                schemaFieldPatterns.stream().filter(pat -> field.matches(pat)).findAny().orElseThrow(() -> new IllegalArgumentException("Fields in the grouping " + fields + " must be a subset the stream fields " + schemaFieldPatterns));
            });
        }
    }
}
Also used : TopologyComponent(com.hortonworks.streamline.streams.catalog.TopologyComponent) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) TopologyOutputComponent(com.hortonworks.streamline.streams.catalog.TopologyOutputComponent) StreamGrouping(com.hortonworks.streamline.streams.catalog.TopologyEdge.StreamGrouping) HashSet(java.util.HashSet)

Aggregations

TopologyComponent (com.hortonworks.streamline.streams.catalog.TopologyComponent)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Topology (com.hortonworks.streamline.streams.catalog.Topology)5 TopologyOutputComponent (com.hortonworks.streamline.streams.catalog.TopologyOutputComponent)5 Timed (com.codahale.metrics.annotation.Timed)4 TopologyStream (com.hortonworks.streamline.streams.catalog.TopologyStream)4 StreamlineProcessor (com.hortonworks.streamline.streams.layout.component.StreamlineProcessor)4 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)4 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 Stream (com.hortonworks.streamline.streams.layout.component.Stream)3 Map (java.util.Map)3 GET (javax.ws.rs.GET)3 QueryParam (com.hortonworks.registries.common.QueryParam)2 TopologyBranchRule (com.hortonworks.streamline.streams.catalog.TopologyBranchRule)2 StreamGrouping (com.hortonworks.streamline.streams.catalog.TopologyEdge.StreamGrouping)2 TopologyRule (com.hortonworks.streamline.streams.catalog.TopologyRule)2 RulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor)2 Rule (com.hortonworks.streamline.streams.layout.component.rule.Rule)2 IOException (java.io.IOException)2