Search in sources :

Example 1 with CustomProcessorOnlyException

use of com.hortonworks.streamline.common.exception.service.exception.request.CustomProcessorOnlyException in project streamline by hortonworks.

the class TopologyComponentBundleResource method updateCustomProcessor.

@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/componentbundles/{processor}/custom")
@Timed
public Response updateCustomProcessor(@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/updating custom processor");
            throw BadRequestException.missingParameter(missingParam);
        }
        CustomProcessorInfo customProcessorInfo = new ObjectMapper().readValue(customProcessorInfoStr, CustomProcessorInfo.class);
        CustomProcessorInfo updatedCustomProcessor = catalogService.updateCustomProcessorInfoAsBundle(customProcessorInfo, jarFile, true);
        return WSUtils.respondEntity(updatedCustomProcessor, OK);
    }
}
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) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 2 with CustomProcessorOnlyException

use of com.hortonworks.streamline.common.exception.service.exception.request.CustomProcessorOnlyException in project streamline by hortonworks.

the class TopologyComponentBundleResource method removeCustomProcessorInfo.

@DELETE
@Path("/componentbundles/{processor}/custom/{name}")
@Timed
public Response removeCustomProcessorInfo(@PathParam("processor") TopologyComponentBundle.TopologyComponentType componentType, @PathParam("name") String name, @Context SecurityContext securityContext) throws IOException {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_ADMIN);
    if (!TopologyComponentBundle.TopologyComponentType.PROCESSOR.equals(componentType)) {
        throw new CustomProcessorOnlyException();
    }
    CustomProcessorInfo removedCustomProcessorInfo = catalogService.removeCustomProcessorInfoAsBundle(name);
    if (removedCustomProcessorInfo != null) {
        return WSUtils.respondEntity(removedCustomProcessorInfo, OK);
    }
    throw EntityNotFoundException.byName(name);
}
Also used : CustomProcessorOnlyException(com.hortonworks.streamline.common.exception.service.exception.request.CustomProcessorOnlyException) CustomProcessorInfo(com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with CustomProcessorOnlyException

use of com.hortonworks.streamline.common.exception.service.exception.request.CustomProcessorOnlyException 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 4 with CustomProcessorOnlyException

use of com.hortonworks.streamline.common.exception.service.exception.request.CustomProcessorOnlyException 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

Timed (com.codahale.metrics.annotation.Timed)4 CustomProcessorOnlyException (com.hortonworks.streamline.common.exception.service.exception.request.CustomProcessorOnlyException)4 CustomProcessorInfo (com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo)4 Path (javax.ws.rs.Path)4 InputStream (java.io.InputStream)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Consumes (javax.ws.rs.Consumes)2 QueryParam (com.hortonworks.registries.common.QueryParam)1 ArrayList (java.util.ArrayList)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Produces (javax.ws.rs.Produces)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1