use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.
the class TopologyCatalogResource method removeTopology.
@DELETE
@Path("/topologies/{topologyId}")
@Timed
public Response removeTopology(@PathParam("topologyId") Long topologyId, @javax.ws.rs.QueryParam("onlyCurrent") boolean onlyCurrent, @javax.ws.rs.QueryParam("force") boolean force, @Context SecurityContext securityContext) throws Exception {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, NAMESPACE, topologyId, DELETE);
if (!force) {
Topology result = catalogService.getTopology(topologyId);
if (result == null) {
throw EntityNotFoundException.byId(topologyId.toString());
}
String asUser = WSUtils.getUserFromSecurityContext(securityContext);
try {
String runtimeTopologyId = actionsService.getRuntimeTopologyId(result, asUser);
if (StringUtils.isNotEmpty(runtimeTopologyId)) {
throw BadRequestException.message("Can't remove topology while Topology is running - topology id: " + topologyId);
}
} catch (TopologyNotAliveException e) {
// OK to continue
} catch (StormNotReachableException | IOException e) {
// users need to make a request with force parameter on
throw new StreamingEngineNotReachableException(e.getMessage(), e);
}
}
Response response;
if (onlyCurrent) {
response = removeCurrentTopologyVersion(topologyId);
} else {
response = removeAllTopologyVersions(topologyId);
}
SecurityUtil.removeAcl(authorizer, securityContext, NAMESPACE, topologyId);
return response;
}
use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.
the class TopologyCatalogResource method removeAllTopologyVersions.
private Response removeAllTopologyVersions(Long topologyId) {
Collection<TopologyVersion> versions = catalogService.listTopologyVersionInfos(WSUtils.topologyVersionsQueryParam(topologyId));
Long currentVersionId = catalogService.getCurrentVersionId(topologyId);
Topology res = null;
for (TopologyVersion version : versions) {
Topology removed = catalogService.removeTopology(topologyId, version.getId(), true);
if (removed != null && removed.getVersionId().equals(currentVersionId)) {
res = removed;
}
}
// remove topology state information
catalogService.removeTopologyState(topologyId);
if (res != null) {
return WSUtils.respondEntity(res, OK);
} else {
throw EntityNotFoundException.byId(topologyId.toString());
}
}
use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.
the class TopologyDashboardResource method listTopologies.
@GET
@Path("/topologies/dashboard")
@Timed
public Response listTopologies(@javax.ws.rs.QueryParam("sort") String sortType, @javax.ws.rs.QueryParam("ascending") Boolean ascending, @javax.ws.rs.QueryParam("latencyTopN") Integer latencyTopN, @Context SecurityContext securityContext) {
Collection<Topology> topologies = catalogService.listTopologies();
boolean topologyUser = SecurityUtil.hasRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER);
if (topologyUser) {
LOG.debug("Returning all topologies since user has role: {}", Roles.ROLE_TOPOLOGY_USER);
} else {
topologies = SecurityUtil.filter(authorizer, securityContext, NAMESPACE, topologies, READ);
}
Response response;
if (topologies != null) {
if (sortType == null) {
sortType = DEFAULT_SORT_TYPE;
}
if (ascending == null) {
ascending = DEFAULT_SORT_ORDER_ASCENDING;
}
String asUser = WSUtils.getUserFromSecurityContext(securityContext);
List<CatalogResourceUtil.TopologyDashboardResponse> detailedTopologies = enrichTopologies(topologies, asUser, sortType, ascending, latencyTopN);
response = WSUtils.respondEntities(detailedTopologies, OK);
} else {
response = WSUtils.respondEntities(Collections.emptyList(), OK);
}
return response;
}
use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.
the class TopologyEventSamplingResource method enableSampling.
@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());
}
use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.
the class TopologyEventSamplingResource method samplingStatus.
@GET
@Path("/topologies/{topologyId}/sampling")
@Timed
public Response samplingStatus(@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);
TopologySampling.SamplingStatus status = samplingService.samplingStatus(topology, asUser);
SamplingResponse response;
if (status == null) {
response = SamplingResponse.of(topologyId).success(false).build();
} else {
response = SamplingResponse.of(topologyId).success(true).enabled(status.getEnabled()).pct(status.getPct()).build();
}
return WSUtils.respondEntity(response, OK);
}
throw EntityNotFoundException.byId(topologyId.toString());
}
Aggregations