@POST @Path("/topologies/{topologyId}/versions/{versionId}/actions/kill") @Timed public Response killTopologyVersion(@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.killTopology(result, WSUtils.getUserFromSecurityContext(securityContext)); return WSUtils.respondEntity(result, OK); } throw EntityNotFoundException.byVersion(topologyId.toString(), versionId.toString()); }
@POST @Path("/topologies/{topologyId}/versions/{versionId}/actions/suspend") @Timed public Response suspendTopologyVersion(@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.suspendTopology(result, WSUtils.getUserFromSecurityContext(securityContext)); return WSUtils.respondEntity(result, OK); } throw EntityNotFoundException.byVersion(topologyId.toString(), versionId.toString()); }
@POST @Path("/topologies/{topologyId}/actions/kill") @Timed public Response killTopology (@PathParam("topologyId") Long topologyId, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, NAMESPACE, topologyId, READ, EXECUTE); Topology result = catalogService.getTopology(topologyId); if (result != null) { actionsService.killTopology(result, WSUtils.getUserFromSecurityContext(securityContext)); return WSUtils.respondEntity(result, OK); } throw EntityNotFoundException.byId(topologyId.toString()); }
@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()); }
@POST @Path("/topologies/{topologyId}/actions/suspend") @Timed public Response suspendTopology (@PathParam("topologyId") Long topologyId, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, NAMESPACE, topologyId, READ, EXECUTE); Topology result = catalogService.getTopology(topologyId); if (result != null) { actionsService.suspendTopology(result, WSUtils.getUserFromSecurityContext(securityContext)); return WSUtils.respondEntity(result, OK); } throw EntityNotFoundException.byId(topologyId.toString()); }
@GET @Path("/topologies/{topologyId}/versions/{versionId}/actions/status") @Timed public Response topologyStatusVersion(@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) { String asUser = WSUtils.getUserFromSecurityContext(securityContext); TopologyActions.Status status = actionsService.topologyStatus(result, asUser); return WSUtils.respondEntity(status, OK); } throw EntityNotFoundException.byVersion(topologyId.toString(), versionId.toString()); }
@POST @Path("/topologies/{topologyId}/actions/resume") @Timed public Response resumeTopology (@PathParam("topologyId") Long topologyId, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, NAMESPACE, topologyId, READ, EXECUTE); Topology result = catalogService.getTopology(topologyId); if (result != null) { actionsService.resumeTopology(result, WSUtils.getUserFromSecurityContext(securityContext)); return WSUtils.respondEntity(result, OK); } throw EntityNotFoundException.byId(topologyId.toString()); }
@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()); }
@GET @Path("/topologies/{topologyId}/versions/{versionId}/dashboard") @Timed public Response getTopologyByIdAndVersion(@PathParam("topologyId") Long topologyId, @PathParam("versionId") Long versionId, @javax.ws.rs.QueryParam("latencyTopN") Integer latencyTopN, @Context SecurityContext securityContext) { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, NAMESPACE, topologyId, READ); String asUser = WSUtils.getUserFromSecurityContext(securityContext); Topology result = catalogService.getTopology(topologyId, versionId); if (result != null) { CatalogResourceUtil.TopologyDashboardResponse topologyDetailed = CatalogResourceUtil.enrichTopology(result, asUser, latencyTopN, environmentService, actionsService, metricsService, catalogService); return WSUtils.respondEntity(topologyDetailed, OK); } throw EntityNotFoundException.byId(topologyId.toString()); }
@GET @Path("/topologies/{topologyId}/actions/status") @Timed public Response topologyStatus (@PathParam("topologyId") Long topologyId, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, NAMESPACE, topologyId, READ, EXECUTE); Topology result = catalogService.getTopology(topologyId); if (result != null) { String asUser = WSUtils.getUserFromSecurityContext(securityContext); TopologyActions.Status status = actionsService.topologyStatus(result, asUser); return WSUtils.respondEntity(status, OK); } throw EntityNotFoundException.byId(topologyId.toString()); }
@GET @Path("/topologies/{topologyId}/dashboard") @Timed public Response getTopologyById(@PathParam("topologyId") Long topologyId, @javax.ws.rs.QueryParam("latencyTopN") Integer latencyTopN, @Context SecurityContext securityContext) { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, NAMESPACE, topologyId, READ); String asUser = WSUtils.getUserFromSecurityContext(securityContext); Topology result = catalogService.getTopology(topologyId); if (result != null) { CatalogResourceUtil.TopologyDashboardResponse topologyDetailed = CatalogResourceUtil.enrichTopology(result, asUser, latencyTopN, environmentService, actionsService, metricsService, catalogService); return WSUtils.respondEntity(topologyDetailed, OK); } throw EntityNotFoundException.byId(topologyId.toString()); }
@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()); }
@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()); } }
@POST @Path("/topologies/{topologyId}/sampling/disable") @Timed public Response disableSampling(@PathParam("topologyId") Long topologyId, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, Topology.NAMESPACE, topologyId, READ, EXECUTE); Topology topology = catalogService.getTopology(topologyId); if (topology != null) { String asUser = WSUtils.getUserFromSecurityContext(securityContext); boolean success = samplingService.disableSampling(topology, asUser); return WSUtils.respondEntity(SamplingResponse.of(topologyId).success(success).build(), OK); } throw EntityNotFoundException.byId(topologyId.toString()); }
private Response deploy(Topology topology, SecurityContext securityContext) { String asUser = WSUtils.getUserFromSecurityContext(securityContext); try { ParallelStreamUtil.runAsync(() -> actionsService.deployTopology(topology, asUser), forkJoinPool); return WSUtils.respondEntity(topology, OK); } catch (TopologyAlreadyExistsOnCluster ex) { return ex.getResponse(); } }
@POST @Path("/topologies/{topologyId}/sampling/enable/{pct}") @Timed public Response enableSampling(@PathParam("topologyId") Long topologyId, @PathParam("pct") Integer pct, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, Topology.NAMESPACE, topologyId, READ, EXECUTE); Topology topology = catalogService.getTopology(topologyId); ensureValidSamplingPct(pct); if (topology != null) { String asUser = WSUtils.getUserFromSecurityContext(securityContext); boolean success = samplingService.enableSampling(topology, pct, asUser); return WSUtils.respondEntity(SamplingResponse.of(topologyId).pct(pct).success(success).build(), OK); } throw EntityNotFoundException.byId(topologyId.toString()); }
@POST @Path("/topologies/{topologyId}/logconfig") @Timed public Response configureLogLevel(@PathParam("topologyId") Long topologyId, @QueryParam("targetLogLevel") TopologyActions.LogLevel targetLogLevel, @QueryParam("durationSecs") int durationSecs, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, NAMESPACE, topologyId, READ); Topology topology = catalogService.getTopology(topologyId); if (topology != null) { TopologyActions.LogLevelInformation logInfo = actionsService.configureLogLevel(topology, targetLogLevel, durationSecs, WSUtils.getUserFromSecurityContext(securityContext)); LogLevelResponse response; if (logInfo != null) { response = LogLevelResponse.succeed().of(logInfo).build(); } else { response = LogLevelResponse.fail().build(); } return WSUtils.respondEntity(response, OK); } throw EntityNotFoundException.byId(topologyId.toString()); }
@GET @Path("/topologies/{topologyId}/logconfig") @Timed public Response getLogLevel(@PathParam("topologyId") Long topologyId, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, NAMESPACE, topologyId, READ); Topology topology = catalogService.getTopology(topologyId); if (topology != null) { TopologyActions.LogLevelInformation logInfo = actionsService.getLogLevel(topology, WSUtils.getUserFromSecurityContext(securityContext)); LogLevelResponse response; if (logInfo != null) { response = LogLevelResponse.succeed().of(logInfo).build(); } else { response = LogLevelResponse.fail().build(); } return WSUtils.respondEntity(response, OK); } throw EntityNotFoundException.byId(topologyId.toString()); }
@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)); }
@POST @Path("/topologies/{topologyId}/component/{componentId}/sampling/enable/{pct}") @Timed public Response enableSampling(@PathParam("topologyId") Long topologyId, @PathParam("componentId") Long componentId, @PathParam("pct") Integer pct, @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); ensureValidSamplingPct(pct); if (topology != null && topologyComponent != null) { String asUser = WSUtils.getUserFromSecurityContext(securityContext); boolean success = samplingService.enableSampling(topology, topologyComponent, pct, asUser); return WSUtils.respondEntity(SamplingResponse.of(topologyId) .componentId(componentId) .pct(pct) .success(success) .build(), OK); } throw EntityNotFoundException.byId(buildTopologyComponentId(topologyId, componentId)); }