/** * Downloads a given {@link File} resource for given {@code fileId} * * @param fileId */ @Timed @GET @Produces({"application/octet-stream", "application/json"}) @Path("/files/download/{fileId}") public Response downloadFile(@PathParam("fileId") Long fileId, @Context SecurityContext securityContext) throws IOException { SecurityUtil.checkPermissions(authorizer, securityContext, File.NAMESPACE, fileId, READ, EXECUTE); File file = catalogService.getFile(fileId); if (file != null) { StreamingOutput streamOutput = WSUtils.wrapWithStreamingOutput(catalogService.downloadFileFromStorage(file.getStoredFileName())); return Response.ok(streamOutput).build(); } throw EntityNotFoundException.byId(fileId.toString()); }
/** * Download the jar corresponding to a specific UDF. * <p> * E.g. curl http://localhost:8080/api/v1/catalog/udfs/download/34 -o /tmp/file.jar * </p> */ @Timed @GET @Produces({"application/java-archive", "application/json"}) @Path("/udfs/download/{udfId}") public Response downloadUdf(@PathParam("udfId") Long udfId, @Context SecurityContext securityContext) throws IOException { SecurityUtil.checkPermissions(authorizer, securityContext, UDF.NAMESPACE, udfId, READ, EXECUTE); UDF udf = catalogService.getUDF(udfId); if (udf != null) { StreamingOutput streamOutput = WSUtils.wrapWithStreamingOutput( catalogService.downloadFileFromStorage(udf.getJarStoragePath())); return Response.ok(streamOutput).build(); } throw EntityNotFoundException.byId(udfId.toString()); }
/** * Download the jar corresponding to a specific Notifier. * <p> * E.g. curl http://localhost:8080/api/v1/catalog/notifiers/download/34 -o /tmp/notifier.jar * </p> */ @Timed @GET @Produces({"application/java-archive", "application/json"}) @Path("/notifiers/download/{notifierId}") public Response downloadNotifier(@PathParam("notifierId") Long notifierId, @Context SecurityContext securityContext) throws IOException { SecurityUtil.checkPermissions(authorizer, securityContext, Notifier.NAMESPACE, notifierId, READ, EXECUTE); Notifier notifier = catalogService.getNotifierInfo(notifierId); if (notifier != null) { StreamingOutput streamOutput = WSUtils.wrapWithStreamingOutput( catalogService.downloadFileFromStorage(notifier.getJarFileName())); return Response.ok(streamOutput).build(); } throw EntityNotFoundException.byId(notifierId.toString()); }
@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); }