use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class TopologySamplingService method getSamplingInstance.
private TopologySampling getSamplingInstance(Topology topology) {
Namespace namespace = environmentService.getNamespace(topology.getNamespaceId());
if (namespace == null) {
throw new RuntimeException("Corresponding namespace not found: " + topology.getNamespaceId());
}
TopologySampling topologySampling = topologySamplingContainer.findInstance(namespace);
if (topologySampling == null) {
throw new RuntimeException("Can't find Topology sampling for such namespace " + topology.getNamespaceId());
}
return topologySampling;
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class CatalogResourceUtil method enrichTopology.
static TopologyDashboardResponse enrichTopology(Topology topology, String asUser, Integer latencyTopN, EnvironmentService environmentService, TopologyActionsService actionsService, TopologyMetricsService metricsService, StreamCatalogService catalogService) {
LOG.debug("[START] enrichTopology - topology id: {}", topology.getId());
Stopwatch stopwatch = Stopwatch.createStarted();
try {
if (latencyTopN == null) {
latencyTopN = DEFAULT_N_OF_TOP_N_LATENCY;
}
TopologyDashboardResponse detailedResponse;
String namespaceName = null;
Namespace namespace = environmentService.getNamespace(topology.getNamespaceId());
if (namespace != null) {
namespaceName = namespace.getName();
}
try {
String runtimeTopologyId = actionsService.getRuntimeTopologyId(topology, asUser);
TopologyMetrics.TopologyMetric topologyMetric = metricsService.getTopologyMetric(topology, asUser);
List<Pair<String, Double>> latenciesTopN = metricsService.getTopNAndOtherComponentsLatency(topology, asUser, latencyTopN);
detailedResponse = new TopologyDashboardResponse(topology, TopologyRunningStatus.RUNNING, namespaceName);
detailedResponse.setRuntime(new TopologyRuntimeResponse(runtimeTopologyId, topologyMetric, latenciesTopN));
} catch (TopologyNotAliveException e) {
LOG.debug("Topology {} is not alive", topology.getId());
detailedResponse = new TopologyDashboardResponse(topology, TopologyRunningStatus.NOT_RUNNING, namespaceName);
catalogService.getTopologyState(topology.getId()).ifPresent(state -> {
if (TopologyStateFactory.getInstance().getTopologyState(state.getName()) == TopologyStates.TOPOLOGY_STATE_DEPLOYED) {
try {
LOG.info("Force killing streamline topology since its not alive in the cluster");
actionsService.killTopology(topology, asUser);
} catch (Exception ex) {
LOG.error("Error trying to kill topology", ex);
}
}
});
} catch (StormNotReachableException | IOException e) {
LOG.error("Storm is not reachable or fail to operate", e);
detailedResponse = new TopologyDashboardResponse(topology, TopologyRunningStatus.UNKNOWN, namespaceName);
} catch (Exception e) {
LOG.error("Unhandled exception occurs while operate with Storm", e);
detailedResponse = new TopologyDashboardResponse(topology, TopologyRunningStatus.UNKNOWN, namespaceName);
}
LOG.debug("[END] enrichTopology - topology id: {}, elapsed: {} ms", topology.getId(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
return detailedResponse;
} finally {
stopwatch.stop();
}
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class NamespaceCatalogResource method getNamespaceById.
@GET
@Path("/namespaces/{id}")
@Timed
public Response getNamespaceById(@PathParam("id") Long namespaceId, @javax.ws.rs.QueryParam("detail") Boolean detail, @Context SecurityContext securityContext) {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_USER, Namespace.NAMESPACE, namespaceId, READ);
Namespace result = environmentService.getNamespace(namespaceId);
if (result != null) {
return buildNamespaceGetResponse(result, detail);
}
throw EntityNotFoundException.byId(namespaceId.toString());
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class NamespaceCatalogResource method setServicesToClusterInNamespace.
@POST
@Path("/namespaces/{id}/mapping/bulk")
@Timed
public Response setServicesToClusterInNamespace(@PathParam("id") Long namespaceId, List<NamespaceServiceClusterMap> mappings, @Context SecurityContext securityContext) {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_SUPER_ADMIN, Namespace.NAMESPACE, namespaceId, WRITE);
Namespace namespace = environmentService.getNamespace(namespaceId);
if (namespace == null) {
throw EntityNotFoundException.byId(namespaceId.toString());
}
String streamingEngine = namespace.getStreamingEngine();
String timeSeriesDB = namespace.getTimeSeriesDB();
Collection<NamespaceServiceClusterMap> existing = environmentService.listServiceClusterMapping(namespaceId);
Optional<NamespaceServiceClusterMap> existingStreamingEngine = existing.stream().filter(m -> m.getServiceName().equals(streamingEngine)).findFirst();
// indicates that mapping of streaming engine has been changed or removed
if (existingStreamingEngine.isPresent() && !mappings.contains(existingStreamingEngine.get())) {
assertNoTopologyReferringNamespaceIsRunning(namespaceId, WSUtils.getUserFromSecurityContext(securityContext));
}
// we're OK to just check with new mappings since we will remove existing mappings
assertServiceIsUnique(mappings, streamingEngine);
assertServiceIsUnique(mappings, timeSeriesDB);
// remove any existing mapping for (namespace, service name) pairs
Collection<NamespaceServiceClusterMap> existingMappings = environmentService.listServiceClusterMapping(namespaceId);
if (existingMappings != null) {
existingMappings.forEach(m -> environmentService.removeServiceClusterMapping(m.getNamespaceId(), m.getServiceName(), m.getClusterId()));
}
List<NamespaceServiceClusterMap> newMappings = mappings.stream().map(environmentService::addOrUpdateServiceClusterMapping).collect(toList());
return WSUtils.respondEntities(newMappings, CREATED);
}
use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.
the class NamespaceCatalogResource method addNamespace.
@Timed
@POST
@Path("/namespaces")
public Response addNamespace(Namespace namespace, @Context SecurityContext securityContext) {
SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_ADMIN);
try {
String namespaceName = namespace.getName();
Namespace result = environmentService.getNamespaceByName(namespaceName);
if (result != null) {
throw new AlreadyExistsException("Namespace entity already exists with name " + namespaceName);
}
Namespace created = environmentService.addNamespace(namespace);
SecurityUtil.addAcl(authorizer, securityContext, Namespace.NAMESPACE, created.getId(), EnumSet.allOf(Permission.class));
return WSUtils.respondEntity(created, CREATED);
} catch (ProcessingException ex) {
throw BadRequestException.of();
}
}
Aggregations