use of com.hortonworks.streamline.streams.cluster.bundle.ComponentBundleHintProvider in project streamline by hortonworks.
the class TopologyComponentBundleResource method getFieldHints.
@GET
@Path("/componentbundles/{component}/{id}/hints/namespaces/{namespaceId}")
@Timed
public Response getFieldHints(@PathParam("component") TopologyComponentBundle.TopologyComponentType componentType, @PathParam("id") Long id, @PathParam("namespaceId") Long namespaceId, @Context SecurityContext securityContext) throws Exception {
SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_USER);
TopologyComponentBundle bundle = catalogService.getTopologyComponentBundle(id);
if (bundle == null || !bundle.getType().equals(componentType)) {
throw EntityNotFoundException.byId("component bundle id: " + id + " with type: " + componentType);
}
String providerClass = bundle.getFieldHintProviderClass();
if (StringUtils.isNotEmpty(providerClass)) {
ComponentBundleHintProvider provider;
if (bundle.getBuiltin()) {
Class<ComponentBundleHintProvider> clazz = (Class<ComponentBundleHintProvider>) Class.forName(providerClass);
provider = clazz.newInstance();
} else {
provider = hintProviderProxyUtil.loadClassFromJar(bundle.getBundleJar(), providerClass);
}
provider.init(environmentService);
Namespace namespace = environmentService.getNamespace(namespaceId);
if (namespace == null) {
throw EntityNotFoundException.byId("namespace id: " + namespaceId);
}
Map<Long, ComponentBundleHintProvider.BundleHintsResponse> hints = provider.provide(namespace, securityContext, subject);
return WSUtils.respondEntity(hints, OK);
} else {
return WSUtils.respondEntity(Collections.emptyMap(), OK);
}
}
Aggregations