Search in sources :

Example 1 with ComponentBundleHintProvider

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);
    }
}
Also used : ComponentBundleHintProvider(com.hortonworks.streamline.streams.cluster.bundle.ComponentBundleHintProvider) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)1 TopologyComponentBundle (com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)1 ComponentBundleHintProvider (com.hortonworks.streamline.streams.cluster.bundle.ComponentBundleHintProvider)1 Namespace (com.hortonworks.streamline.streams.cluster.catalog.Namespace)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1