Search in sources :

Example 11 with CustomProcessorInfo

use of com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo in project streamline by hortonworks.

the class TopologyComponentBundleResource method downloadCustomProcessorFile.

@Timed
@GET
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Path("/componentbundles/{processor}/custom/{name}")
public Response downloadCustomProcessorFile(@PathParam("processor") TopologyComponentBundle.TopologyComponentType componentType, @PathParam("name") String name, @Context SecurityContext securityContext) throws IOException {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_USER);
    if (!TopologyComponentBundle.TopologyComponentType.PROCESSOR.equals(componentType)) {
        throw new CustomProcessorOnlyException();
    }
    List<QueryParam> queryParams = new ArrayList<>();
    queryParams.add(new QueryParam(CustomProcessorInfo.NAME, name));
    Collection<CustomProcessorInfo> customProcessorInfos = catalogService.listCustomProcessorsFromBundleWithFilter(queryParams);
    if (!customProcessorInfos.isEmpty()) {
        final InputStream inputStream = catalogService.getFileFromJarStorage(customProcessorInfos.iterator().next().getJarFileName());
        StreamingOutput streamOutput = WSUtils.wrapWithStreamingOutput(inputStream);
        return Response.ok(streamOutput).build();
    }
    throw EntityNotFoundException.byId(name);
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) StreamingOutput(javax.ws.rs.core.StreamingOutput) CustomProcessorOnlyException(com.hortonworks.streamline.common.exception.service.exception.request.CustomProcessorOnlyException) CustomProcessorInfo(com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 12 with CustomProcessorInfo

use of com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo in project streamline by hortonworks.

the class TopologyComponentBundleResource method addCustomProcessor.

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/componentbundles/{processor}/custom")
@Timed
public Response addCustomProcessor(@PathParam("processor") TopologyComponentBundle.TopologyComponentType componentType, FormDataMultiPart form, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_ADMIN);
    if (!TopologyComponentBundle.TopologyComponentType.PROCESSOR.equals(componentType)) {
        throw new CustomProcessorOnlyException();
    }
    try (InputStream jarFile = this.getFormDataFromMultiPartRequestAs(InputStream.class, form, JAR_FILE_PARAM_NAME)) {
        String customProcessorInfoStr = this.getFormDataFromMultiPartRequestAs(String.class, form, CP_INFO_PARAM_NAME);
        String missingParam = (jarFile == null ? JAR_FILE_PARAM_NAME : (customProcessorInfoStr == null ? CP_INFO_PARAM_NAME : null));
        if (missingParam != null) {
            LOG.debug(missingParam + " is missing or invalid while adding custom processor");
            throw BadRequestException.missingParameter(missingParam);
        }
        CustomProcessorInfo customProcessorInfo = new ObjectMapper().readValue(customProcessorInfoStr, CustomProcessorInfo.class);
        CustomProcessorInfo createdCustomProcessor = catalogService.addCustomProcessorInfoAsBundle(customProcessorInfo, jarFile);
        return WSUtils.respondEntity(createdCustomProcessor, CREATED);
    }
}
Also used : InputStream(java.io.InputStream) CustomProcessorOnlyException(com.hortonworks.streamline.common.exception.service.exception.request.CustomProcessorOnlyException) CustomProcessorInfo(com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

CustomProcessorInfo (com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo)12 InputStream (java.io.InputStream)6 Timed (com.codahale.metrics.annotation.Timed)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 CustomProcessorOnlyException (com.hortonworks.streamline.common.exception.service.exception.request.CustomProcessorOnlyException)4 FileInputStream (java.io.FileInputStream)4 Path (javax.ws.rs.Path)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 QueryParam (com.hortonworks.registries.common.QueryParam)2 IOException (java.io.IOException)2 Consumes (javax.ws.rs.Consumes)2 Test (org.junit.Test)2 ComponentConfigException (com.hortonworks.streamline.common.exception.ComponentConfigException)1 IntegrationTest (com.hortonworks.streamline.common.test.IntegrationTest)1 WSUtils.buildEdgesFromQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam)1 WSUtils.buildEdgesToQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam)1 WSUtils.currentVersionQueryParam (com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam)1 WSUtils.versionIdQueryParam (com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam)1 TopologyComponentBundle (com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)1