use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.
the class UDFCatalogResource method addOrUpdateUDF.
/**
* Update a udf.
* <p>
* curl -X PUT 'http://localhost:8080/api/v1/catalog/udfs/34'
* -F udfJarFile=@/tmp/streams-functions-0.6.0-SNAPSHOT.jar
* -F udfConfig='{"name":"stddev", "description": "stddev",
* "type":"AGGREGATE", "className":"com.hortonworks.streamline.streams.rule.udaf.Stddev"};type=application/json'
* </p>
* <pre>
* {
* "responseCode": 1000,
* "responseMessage": "Success",
* "entity": {
* "id": 48,
* "name": "SUBSTRING",
* "description": "Substring",
* "type": "FUNCTION",
* "className": "builtin"
* }
* }
* </pre>
*/
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/udfs/{id}")
@Timed
public Response addOrUpdateUDF(@PathParam("id") Long udfId, @FormDataParam("udfJarFile") final InputStream inputStream, @FormDataParam("udfJarFile") final FormDataContentDisposition contentDispositionHeader, @FormDataParam("udfConfig") final FormDataBodyPart udfConfig, @FormDataParam("builtin") final boolean builtin, @Context SecurityContext securityContext) throws Exception {
SecurityUtil.checkPermissions(authorizer, securityContext, UDF.NAMESPACE, udfId, WRITE);
MediaType mediaType = udfConfig.getMediaType();
LOG.debug("Media type {}", mediaType);
if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
throw new UnsupportedMediaTypeException(mediaType.toString());
}
UDF udf = udfConfig.getValueAs(UDF.class);
processUdf(inputStream, udf, false, builtin);
UDF newUdf = catalogService.addOrUpdateUDF(udfId, udf);
return WSUtils.respondEntity(newUdf, CREATED);
}
use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.
the class UDFCatalogResource method removeUDF.
/**
* Remove a UDF by ID.
*
* <p>
* DELETE api/v1/catalog/udfs/:ID
* </p>
* <pre>
* {
* "responseCode": 1000,
* "responseMessage": "Success",
* "entity": {
* "id": 48,
* "name": "SUBSTRING",
* "description": "Substring",
* "type": "FUNCTION",
* "className": "builtin"
* }
* }
* </pre>
*/
@DELETE
@Path("/udfs/{id}")
@Timed
public Response removeUDF(@PathParam("id") Long id, @Context SecurityContext securityContext) {
SecurityUtil.checkPermissions(authorizer, securityContext, UDF.NAMESPACE, id, DELETE);
UDF removedUDF = catalogService.removeUDF(id);
if (removedUDF != null) {
SecurityUtil.removeAcl(authorizer, securityContext, UDF.NAMESPACE, id);
return WSUtils.respondEntity(removedUDF, OK);
}
throw EntityNotFoundException.byId(id.toString());
}
use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.
the class UDFCatalogResource method downloadUdf.
/**
* 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());
}
use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.
the class UDFCatalogResource method getUDFById.
/**
* Get a specific UDF by id.
*
* <p>
* GET api/v1/catalog/udfs/:ID
* </p>
* <pre>
* {
* "responseCode": 1000,
* "responseMessage": "Success",
* "entity": {
* "id": 48,
* "name": "SUBSTRING",
* "description": "Substring",
* "type": "FUNCTION",
* "className": "builtin"
* }
* }
* </pre>
*/
@GET
@Path("/udfs/{id}")
@Timed
public Response getUDFById(@PathParam("id") Long id, @Context SecurityContext securityContext) {
boolean udfUser = SecurityUtil.hasRole(authorizer, securityContext, Roles.ROLE_UDF_USER);
if (udfUser) {
LOG.debug("Allowing get UDF, since user has role: {}", Roles.ROLE_UDF_USER);
} else {
SecurityUtil.checkPermissions(authorizer, securityContext, UDF.NAMESPACE, id, READ);
}
UDF result = catalogService.getUDF(id);
if (result != null) {
return WSUtils.respondEntity(result, OK);
}
throw EntityNotFoundException.byId(id.toString());
}
use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.
the class UDFCatalogResource method addUDF.
/**
* Add a new UDF.
* <p>
* curl -X POST 'http://localhost:8080/api/v1/catalog/udfs' -F udfJarFile=/tmp/foo-function.jar
* -F udfConfig='{"name":"Foo", "description": "testing", "type":"FUNCTION", "className":"com.test.Foo"};type=application/json'
* </p>
*/
@Timed
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/udfs")
public Response addUDF(@FormDataParam("udfJarFile") final InputStream inputStream, @FormDataParam("udfJarFile") final FormDataContentDisposition contentDispositionHeader, @FormDataParam("udfConfig") final FormDataBodyPart udfConfig, @FormDataParam("builtin") final boolean builtin, @Context SecurityContext securityContext) throws Exception {
SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_UDF_ADMIN);
MediaType mediaType = udfConfig.getMediaType();
LOG.debug("Media type {}", mediaType);
if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
throw new UnsupportedMediaTypeException(mediaType.toString());
}
UDF udf = udfConfig.getValueAs(UDF.class);
processUdf(inputStream, udf, true, builtin);
UDF createdUdf = catalogService.addUDF(udf);
SecurityUtil.addAcl(authorizer, securityContext, UDF.NAMESPACE, createdUdf.getId(), EnumSet.allOf(Permission.class));
return WSUtils.respondEntity(createdUdf, CREATED);
}
Aggregations