Search in sources :

Example 56 with Topology

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

the class TopologyMetricsService method getTopNAndOtherComponentsLatency.

public List<Pair<String, Double>> getTopNAndOtherComponentsLatency(Topology topology, String asUser, int nOfTopN) throws IOException {
    TopologyMetrics topologyMetrics = getTopologyMetricsInstance(topology);
    Map<String, TopologyMetrics.ComponentMetric> metricsForTopology = topologyMetrics.getMetricsForTopology(CatalogToLayoutConverter.getTopologyLayout(topology), asUser);
    List<Pair<String, Double>> topNAndOther = new ArrayList<>();
    List<ImmutablePair<String, Double>> latencyOrderedComponents = metricsForTopology.entrySet().stream().map((x) -> new ImmutablePair<>(x.getValue().getComponentName(), x.getValue().getProcessedTime())).sorted((c1, c2) -> {
        if (c2.getValue() == null) {
            // assuming c1 is bigger
            return -1;
        } else {
            return c2.getValue().compareTo(c1.getValue());
        }
    }).collect(toList());
    latencyOrderedComponents.stream().limit(nOfTopN).forEachOrdered(topNAndOther::add);
    double sumLatencyOthers = latencyOrderedComponents.stream().skip(nOfTopN).filter((x) -> x.getValue() != null).mapToDouble(Pair::getValue).sum();
    topNAndOther.add(new ImmutablePair<>("Others", sumLatencyOthers));
    return topNAndOther;
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) CatalogToLayoutConverter(com.hortonworks.streamline.streams.catalog.CatalogToLayoutConverter) ContainingNamespaceAwareContainer(com.hortonworks.streamline.streams.cluster.container.ContainingNamespaceAwareContainer) IOException(java.io.IOException) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Subject(javax.security.auth.Subject) ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) TopologyComponent(com.hortonworks.streamline.streams.catalog.TopologyComponent) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Pair(org.apache.commons.lang3.tuple.Pair) TopologyTimeSeriesMetrics(com.hortonworks.streamline.streams.metrics.topology.TopologyTimeSeriesMetrics) TopologyMetricsContainer(com.hortonworks.streamline.streams.metrics.container.TopologyMetricsContainer) Map(java.util.Map) TopologyMetrics(com.hortonworks.streamline.streams.metrics.topology.TopologyMetrics) ArrayList(java.util.ArrayList) TopologyMetrics(com.hortonworks.streamline.streams.metrics.topology.TopologyMetrics) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair)

Example 57 with Topology

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

the class NamespaceCatalogResourceTest method setupExpectationForSimulatingTopologyIsRunning.

private void setupExpectationForSimulatingTopologyIsRunning(final Long testNamespaceId, final Namespace testNamespace, final Collection<NamespaceServiceClusterMap> existingMappings) throws IOException {
    List<Topology> topologies = createTestTopologies(testNamespaceId);
    new Expectations() {

        {
            environmentService.getNamespace(testNamespaceId);
            result = testNamespace;
            environmentService.listServiceClusterMapping(testNamespaceId);
            result = existingMappings;
            catalogService.listTopologies();
            result = topologies;
            // assuming first topology is not running
            topologyActionsService.getRuntimeTopologyId(topologies.get(0), anyString);
            result = new TopologyNotAliveException("generated exception for purpose");
            // and second topology is running now
            topologyActionsService.getRuntimeTopologyId(topologies.get(1), anyString);
            result = "dummy-storm-topology-id";
        }
    };
}
Also used : Expectations(mockit.Expectations) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) Topology(com.hortonworks.streamline.streams.catalog.Topology)

Example 58 with Topology

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

the class NamespaceCatalogResourceTest method createTestTopologies.

private List<Topology> createTestTopologies(Long testNamespaceId) {
    Topology topology1 = new Topology();
    topology1.setId(1L);
    topology1.setName("test-topology-1");
    topology1.setNamespaceId(testNamespaceId);
    topology1.setVersionId(1L);
    Topology topology2 = new Topology();
    topology2.setId(2L);
    topology2.setName("test-topology-2");
    topology2.setNamespaceId(testNamespaceId);
    topology2.setVersionId(1L);
    return Lists.newArrayList(topology1, topology2);
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology)

Example 59 with Topology

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

the class TopologyEventSamplingResource method disableSampling.

@POST
@Path("/topologies/{topologyId}/component/{componentId}/sampling/disable")
@Timed
public Response disableSampling(@PathParam("topologyId") Long topologyId, @PathParam("componentId") Long componentId, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, Topology.NAMESPACE, topologyId, READ, EXECUTE);
    Topology topology = catalogService.getTopology(topologyId);
    TopologyComponent topologyComponent = catalogService.getTopologyComponent(topologyId, componentId);
    if (topology != null && topologyComponent != null) {
        String asUser = WSUtils.getUserFromSecurityContext(securityContext);
        boolean success = samplingService.disableSampling(topology, topologyComponent, asUser);
        return WSUtils.respondEntity(SamplingResponse.of(topologyId).componentId(componentId).success(success).build(), OK);
    }
    throw EntityNotFoundException.byId(buildTopologyComponentId(topologyId, componentId));
}
Also used : TopologyComponent(com.hortonworks.streamline.streams.catalog.TopologyComponent) Topology(com.hortonworks.streamline.streams.catalog.Topology) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 60 with Topology

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

the class TopologyActionResource method resumeTopologyVersion.

@POST
@Path("/topologies/{topologyId}/versions/{versionId}/actions/resume")
@Timed
public Response resumeTopologyVersion(@PathParam("topologyId") Long topologyId, @PathParam("versionId") Long versionId, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, NAMESPACE, topologyId, READ, EXECUTE);
    Topology result = catalogService.getTopology(topologyId, versionId);
    if (result != null) {
        actionsService.resumeTopology(result, WSUtils.getUserFromSecurityContext(securityContext));
        return WSUtils.respondEntity(result, OK);
    }
    throw EntityNotFoundException.byVersion(topologyId.toString(), versionId.toString());
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Topology (com.hortonworks.streamline.streams.catalog.Topology)67 Timed (com.codahale.metrics.annotation.Timed)39 Path (javax.ws.rs.Path)27 GET (javax.ws.rs.GET)17 IOException (java.io.IOException)12 TopologyActions (com.hortonworks.streamline.streams.actions.TopologyActions)9 TopologyTestRunHistory (com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 TopologyTestRunCase (com.hortonworks.streamline.streams.catalog.TopologyTestRunCase)8 List (java.util.List)8 Map (java.util.Map)8 POST (javax.ws.rs.POST)8 Expectations (mockit.Expectations)8 Test (org.junit.Test)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 TopologyComponent (com.hortonworks.streamline.streams.catalog.TopologyComponent)6 TopologyTestRunCaseSource (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)6 ArrayList (java.util.ArrayList)6 StreamCatalogService (com.hortonworks.streamline.streams.catalog.service.StreamCatalogService)5 Collections (java.util.Collections)5