Search in sources :

Example 16 with Topology

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

the class MetricsResource method getTopologyMetricsById.

@GET
@Path("/topologies/{id}")
@Timed
public Response getTopologyMetricsById(@PathParam("id") Long id, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, id, READ);
    Topology topology = catalogService.getTopology(id);
    if (topology != null) {
        String asUser = WSUtils.getUserFromSecurityContext(securityContext);
        Map<String, TopologyMetrics.ComponentMetric> topologyMetrics = metricsService.getTopologyMetrics(topology, asUser);
        return WSUtils.respondEntity(topologyMetrics, OK);
    }
    throw EntityNotFoundException.byId(id.toString());
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 17 with Topology

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

the class MetricsResource method getTopologyMetricsViaTimeSeriesById.

@GET
@Path("/topologies/{id}/timeseries")
@Timed
public Response getTopologyMetricsViaTimeSeriesById(@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) {
        String asUser = WSUtils.getUserFromSecurityContext(securityContext);
        TopologyTimeSeriesMetrics.TimeSeriesComponentMetric topologyMetrics = metricsService.getTopologyStats(topology, from, to, asUser);
        return WSUtils.respondEntity(topologyMetrics, OK);
    }
    throw EntityNotFoundException.byId(id.toString());
}
Also used : TopologyTimeSeriesMetrics(com.hortonworks.streamline.streams.metrics.topology.TopologyTimeSeriesMetrics) Topology(com.hortonworks.streamline.streams.catalog.Topology) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 18 with Topology

use of com.hortonworks.streamline.streams.catalog.Topology 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 19 with Topology

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

the class StreamCatalogService method removeTopology.

public Topology removeTopology(Long topologyId, Long versionId, boolean recurse) {
    Topology topology = new Topology();
    topology.setId(topologyId);
    topology.setVersionId(versionId);
    if (recurse) {
        try {
            removeTopologyDependencies(topology.getId(), topology.getVersionId());
        } catch (Exception ex) {
            LOG.error("Got exception while removing topology dependencies", ex);
            throw new RuntimeException(ex);
        }
    }
    Topology removedTopology = dao.remove(topology.getStorableKey());
    removeTopologyVersionInfo(versionId);
    return removedTopology;
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) ComponentConfigException(com.hortonworks.streamline.common.exception.ComponentConfigException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StorageException(com.hortonworks.registries.storage.exception.StorageException)

Example 20 with Topology

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

the class StreamCatalogServiceTest method testListTopologiesProvidesVersionedTimestamp_STREAMLINE_526.

@Test
public void testListTopologiesProvidesVersionedTimestamp_STREAMLINE_526() {
    List<Topology> topologies = new ArrayList<>();
    topologies.add(createTopology(1L));
    topologies.add(createTopology(2L));
    topologies.add(createTopology(3L));
    List<TopologyVersion> versions = topologies.stream().map(x -> createTopologyVersionInfo(x.getId(), x.getId())).collect(Collectors.toList());
    new Expectations() {

        {
            dao.find(withEqual(new Topology().getNameSpace()), withAny(new ArrayList<>()));
            result = topologies;
            dao.find(withEqual(new TopologyVersion().getNameSpace()), withAny(new ArrayList<>()));
            result = versions;
            dao.get(withEqual(new StorableKey(versions.get(0).getNameSpace(), versions.get(0).getPrimaryKey())));
            result = versions.get(0);
            dao.get(withEqual(new StorableKey(versions.get(1).getNameSpace(), versions.get(1).getPrimaryKey())));
            result = versions.get(1);
            dao.get(withEqual(new StorableKey(versions.get(2).getNameSpace(), versions.get(2).getPrimaryKey())));
            result = versions.get(2);
        }
    };
    Collection<Topology> result = streamCatalogService.listTopologies();
    assertTrue(result.size() > 0);
    assertFalse(result.stream().anyMatch(x -> x.getVersionTimestamp() == null));
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) MLModelRegistryClient(com.hortonworks.streamline.registries.model.client.MLModelRegistryClient) Arrays(java.util.Arrays) Expectations(mockit.Expectations) FileStorage(com.hortonworks.registries.common.util.FileStorage) RunWith(org.junit.runner.RunWith) ArrayList(java.util.ArrayList) Map(java.util.Map) Projection(com.hortonworks.streamline.streams.catalog.Projection) JMockit(mockit.integration.junit4.JMockit) TopologyVersion(com.hortonworks.streamline.streams.catalog.TopologyVersion) Tested(mockit.Tested) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) List(java.util.List) TreeMap(java.util.TreeMap) Assert.assertFalse(org.junit.Assert.assertFalse) Injectable(mockit.Injectable) Assert(org.junit.Assert) StorableKey(com.hortonworks.registries.storage.StorableKey) StorageManager(com.hortonworks.registries.storage.StorageManager) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Expectations(mockit.Expectations) TopologyVersion(com.hortonworks.streamline.streams.catalog.TopologyVersion) StorableKey(com.hortonworks.registries.storage.StorableKey) ArrayList(java.util.ArrayList) Topology(com.hortonworks.streamline.streams.catalog.Topology) Test(org.junit.Test)

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