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);
}
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);
}
}
Aggregations