Search in sources :

Example 21 with TopologyComponentBundle

use of com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle in project streamline by hortonworks.

the class TopologyComponentBundleResource method addOrUpdateTopologyComponentBundleById.

/**
 * Update a topology component bundle by id.
 * <p>
 * curl -sS -X PUT -i -F topologyComponentBundle=@kafka-topology-bundle -F bundleJar=@/Users/pshah/dev/IoTaS/streams/runners/storm/layout/target/streams-layout-storm-0.6.0-SNAPSHOT.jar  http://localhost:8080/api/v1/catalog/streams/componentbundles/SOURCE/1
 * </p>
 */
@PUT
@Path("/componentbundles/{component}/{id}")
@Timed
public Response addOrUpdateTopologyComponentBundleById(@PathParam("component") TopologyComponentBundle.TopologyComponentType componentType, @PathParam("id") Long id, FormDataMultiPart form, @Context SecurityContext securityContext) throws IOException, ComponentConfigException {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_ADMIN);
    InputStream bundleJar = null;
    File tmpFile = null;
    try {
        String bundleJsonString = this.getFormDataFromMultiPartRequestAs(String.class, form, TOPOLOGY_COMPONENT_BUNDLE_PARAM_NAME);
        TopologyComponentBundle topologyComponentBundle = new ObjectMapper().readValue(bundleJsonString, TopologyComponentBundle.class);
        if (topologyComponentBundle == null) {
            LOG.debug(TOPOLOGY_COMPONENT_BUNDLE_PARAM_NAME + " is missing or invalid");
            throw BadRequestException.missingParameter(TOPOLOGY_COMPONENT_BUNDLE_PARAM_NAME);
        }
        if (!topologyComponentBundle.getBuiltin()) {
            bundleJar = this.getFormDataFromMultiPartRequestAs(InputStream.class, form, BUNDLE_JAR_FILE_PARAM_NAME);
            if (bundleJar == null) {
                LOG.debug(BUNDLE_JAR_FILE_PARAM_NAME + " is missing or invalid");
                throw BadRequestException.missingParameter(BUNDLE_JAR_FILE_PARAM_NAME);
            } else {
                tmpFile = FileUtil.writeInputStreamToTempFile(bundleJar, ".jar");
            }
        }
        validateTopologyBundle(topologyComponentBundle);
        topologyComponentBundle.setType(componentType);
        TopologyComponentBundle updatedBundle = catalogService.addOrUpdateTopologyComponentBundle(id, topologyComponentBundle, tmpFile);
        return WSUtils.respondEntity(updatedBundle, OK);
    } catch (RuntimeException e) {
        LOG.debug("Error occured while updating topology component bundle", e);
        throw e;
    } finally {
        try {
            if (bundleJar != null) {
                bundleJar.close();
            }
        } catch (IOException e) {
            LOG.debug("Error while closing jar file stream", e);
        }
    }
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 22 with TopologyComponentBundle

use of com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle in project streamline by hortonworks.

the class TopologyComponentBundleResource method addTopologyComponentBundle.

/**
 * Add a new topology component bundle.
 * <p>
 * curl -sS -X POST -i -F topologyComponentBundle=@kafka-topology-bundle -F bundleJar=@/Users/pshah/dev/IoTaS/streams/runners/storm/layout/target/streams-layout-storm-0.6.0-SNAPSHOT.jar  http://localhost:8080/api/v1/catalog/streams/componentbundles/SOURCE/
 * </p>
 */
@POST
@Path("/componentbundles/{component}")
@Timed
public Response addTopologyComponentBundle(@PathParam("component") TopologyComponentBundle.TopologyComponentType componentType, FormDataMultiPart form, @Context SecurityContext securityContext) throws IOException, ComponentConfigException {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_ADMIN);
    InputStream bundleJar = null;
    File tmpFile = null;
    try {
        String bundleJsonString = this.getFormDataFromMultiPartRequestAs(String.class, form, TOPOLOGY_COMPONENT_BUNDLE_PARAM_NAME);
        TopologyComponentBundle topologyComponentBundle = new ObjectMapper().readValue(bundleJsonString, TopologyComponentBundle.class);
        if (topologyComponentBundle == null) {
            LOG.debug(TOPOLOGY_COMPONENT_BUNDLE_PARAM_NAME + " is missing or invalid");
            throw BadRequestException.missingParameter(TOPOLOGY_COMPONENT_BUNDLE_PARAM_NAME);
        }
        List<QueryParam> queryParams;
        MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
        params.putSingle(TopologyComponentBundle.STREAMING_ENGINE, topologyComponentBundle.getStreamingEngine());
        params.putSingle(TopologyComponentBundle.SUB_TYPE, topologyComponentBundle.getSubType());
        queryParams = WSUtils.buildQueryParameters(params);
        Collection<TopologyComponentBundle> topologyComponentBundles = catalogService.listTopologyComponentBundlesForTypeWithFilter(componentType, queryParams);
        if (topologyComponentBundles != null && !topologyComponentBundles.isEmpty()) {
            LOG.warn("Received a post request for an already registered bundle. Not creating entity for " + topologyComponentBundle);
            return WSUtils.respondEntity(topologyComponentBundle, CONFLICT);
        }
        if (!topologyComponentBundle.getBuiltin()) {
            bundleJar = this.getFormDataFromMultiPartRequestAs(InputStream.class, form, BUNDLE_JAR_FILE_PARAM_NAME);
            if (bundleJar == null) {
                LOG.debug(BUNDLE_JAR_FILE_PARAM_NAME + " is missing or invalid");
                throw BadRequestException.missingParameter(BUNDLE_JAR_FILE_PARAM_NAME);
            } else {
                tmpFile = FileUtil.writeInputStreamToTempFile(bundleJar, ".jar");
            }
        }
        validateTopologyBundle(topologyComponentBundle);
        topologyComponentBundle.setType(componentType);
        TopologyComponentBundle createdBundle = catalogService.addTopologyComponentBundle(topologyComponentBundle, tmpFile);
        return WSUtils.respondEntity(createdBundle, CREATED);
    } catch (RuntimeException e) {
        LOG.debug("Error occured while adding topology component bundle", e);
        throw e;
    } finally {
        try {
            if (bundleJar != null) {
                bundleJar.close();
            }
        } catch (IOException e) {
            LOG.debug("Error while closing jar file stream", e);
        }
    }
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) QueryParam(com.hortonworks.registries.common.QueryParam) InputStream(java.io.InputStream) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 23 with TopologyComponentBundle

use of com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle 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

TopologyComponentBundle (com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)23 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)8 QueryParam (com.hortonworks.registries.common.QueryParam)7 Timed (com.codahale.metrics.annotation.Timed)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Path (javax.ws.rs.Path)6 WSUtils.buildEdgesFromQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam)5 WSUtils.buildEdgesToQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam)5 WSUtils.currentVersionQueryParam (com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam)5 WSUtils.versionIdQueryParam (com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam)5 InputStream (java.io.InputStream)5 TopologyProcessor (com.hortonworks.streamline.streams.catalog.TopologyProcessor)4 ComponentUISpecification (com.hortonworks.streamline.common.ComponentUISpecification)3 File (java.io.File)3 HashMap (java.util.HashMap)3 ImmutableList (com.google.common.collect.ImmutableList)2 StorageException (com.hortonworks.registries.storage.exception.StorageException)2 BaseTopologyRule (com.hortonworks.streamline.streams.catalog.BaseTopologyRule)2 CustomProcessorInfo (com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo)2