Search in sources :

Example 1 with TopologyComponentBundle

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

the class TopologyComponentBundleResource method getTopologyComponentBundleById.

/**
 * Get component bundle registered for a type(SOURCE, SINK, etc) matching the id
 * <p>
 * GET api/v1/catalog/streams/componentbundles/SOURCE/5
 * </p>
 */
@GET
@Path("/componentbundles/{component}/{id}")
@Timed
@Produces(MediaType.APPLICATION_JSON)
public Response getTopologyComponentBundleById(@PathParam("component") TopologyComponentBundle.TopologyComponentType componentType, @PathParam("id") Long id, @Context SecurityContext securityContext) {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_USER);
    TopologyComponentBundle result = catalogService.getTopologyComponentBundle(id);
    if (result != null) {
        return WSUtils.respondEntity(result, OK);
    }
    throw EntityNotFoundException.byId(id.toString());
}
Also used : TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 2 with TopologyComponentBundle

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

the class TopologyComponentBundleResource method addOrUpdateTopologyComponentBundle.

/**
 * Update a topology component bundle by trying to find id using type, sub type and streaming engine.
 * <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/
 * </p>
 */
@PUT
@Path("/componentbundles/{component}")
@Timed
public Response addOrUpdateTopologyComponentBundle(@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);
        }
        if (!componentType.equals(topologyComponentBundle.getType())) {
            String message = "Cant update a " + topologyComponentBundle.getType() + " on " + componentType + " endpoint. Verify PUT request";
            LOG.debug(message);
            throw BadRequestException.message(message);
        }
        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);
        List<QueryParam> queryParams = new ArrayList<>();
        queryParams.add(new QueryParam(TopologyComponentBundle.STREAMING_ENGINE, topologyComponentBundle.getStreamingEngine()));
        queryParams.add(new QueryParam(TopologyComponentBundle.TYPE, topologyComponentBundle.getType().name()));
        queryParams.add(new QueryParam(TopologyComponentBundle.SUB_TYPE, topologyComponentBundle.getSubType()));
        Collection<TopologyComponentBundle> existing = catalogService.listTopologyComponentBundlesForTypeWithFilter(componentType, queryParams);
        if (existing != null && existing.size() == 1) {
            TopologyComponentBundle updatedBundle = catalogService.addOrUpdateTopologyComponentBundle(existing.iterator().next().getId(), topologyComponentBundle, tmpFile);
            return WSUtils.respondEntity(updatedBundle, OK);
        } else {
            String message = "Cant update because lookup using streaming engine, type and subtype returned either no existing bundle or more than one";
            LOG.debug(message);
            throw BadRequestException.message(message);
        }
    } 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 : QueryParam(com.hortonworks.registries.common.QueryParam) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) 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 3 with TopologyComponentBundle

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

the class StreamCatalogService method removeTopologyComponentBundle.

public TopologyComponentBundle removeTopologyComponentBundle(Long id) throws IOException {
    TopologyComponentBundle topologyComponentBundle = new TopologyComponentBundle();
    topologyComponentBundle.setId(id);
    TopologyComponentBundle existing = this.dao.get(topologyComponentBundle.getStorableKey());
    if (!existing.getBuiltin()) {
        deleteFileFromStorage(existing.getBundleJar());
    }
    return dao.remove(existing.getStorableKey());
}
Also used : TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)

Example 4 with TopologyComponentBundle

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

the class StreamCatalogService method getTopologyComponentBundle.

public TopologyComponentBundle getTopologyComponentBundle(Long topologyComponentBundleId) {
    TopologyComponentBundle topologyComponentBundle = new TopologyComponentBundle();
    topologyComponentBundle.setId(topologyComponentBundleId);
    return this.dao.get(topologyComponentBundle.getStorableKey());
}
Also used : TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)

Example 5 with TopologyComponentBundle

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

the class StreamCatalogService method addCustomProcessorInfoAsBundle.

public CustomProcessorInfo addCustomProcessorInfoAsBundle(CustomProcessorInfo customProcessorInfo, InputStream jarFile) throws IOException, ComponentConfigException, NoSuchAlgorithmException {
    List<QueryParam> queryParams = new ArrayList<>();
    queryParams.add(new QueryParam(CustomProcessorInfo.NAME, customProcessorInfo.getName()));
    Collection<TopologyComponentBundle> result = this.listCustomProcessorBundlesWithFilter(queryParams);
    if (!result.isEmpty()) {
        throw new IOException("Custom processor already exists with name:" + customProcessorInfo.getName());
    }
    this.handleCustomProcessorJar(jarFile, customProcessorInfo, true);
    TopologyComponentBundle topologyComponentBundle = customProcessorInfo.toTopologyComponentBundle();
    this.addTopologyComponentBundle(topologyComponentBundle, null);
    return customProcessorInfo;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) WSUtils.versionIdQueryParam(com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam) WSUtils.buildEdgesFromQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam) WSUtils.currentVersionQueryParam(com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam) WSUtils.buildEdgesToQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)

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