Search in sources :

Example 1 with UnsupportedMediaTypeException

use of com.hortonworks.streamline.common.exception.service.exception.request.UnsupportedMediaTypeException 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);
}
Also used : UnsupportedMediaTypeException(com.hortonworks.streamline.common.exception.service.exception.request.UnsupportedMediaTypeException) UDF(com.hortonworks.streamline.streams.catalog.UDF) MediaType(javax.ws.rs.core.MediaType) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 2 with UnsupportedMediaTypeException

use of com.hortonworks.streamline.common.exception.service.exception.request.UnsupportedMediaTypeException 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);
}
Also used : UnsupportedMediaTypeException(com.hortonworks.streamline.common.exception.service.exception.request.UnsupportedMediaTypeException) UDF(com.hortonworks.streamline.streams.catalog.UDF) Permission(com.hortonworks.streamline.streams.security.Permission) MediaType(javax.ws.rs.core.MediaType) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with UnsupportedMediaTypeException

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

the class NotifierInfoCatalogResource method addOrUpdateNotifierInfo.

@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/notifiers/{id}")
@Timed
public Response addOrUpdateNotifierInfo(@PathParam("id") Long id, @FormDataParam("notifierJarFile") final InputStream inputStream, @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader, @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig, @Context SecurityContext securityContext) throws IOException {
    SecurityUtil.checkPermissions(authorizer, securityContext, Notifier.NAMESPACE, id, WRITE);
    MediaType mediaType = notifierConfig.getMediaType();
    LOG.debug("Media type {}", mediaType);
    if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
        throw new UnsupportedMediaTypeException(mediaType.toString());
    }
    Notifier notifier = notifierConfig.getValueAs(Notifier.class);
    String jarFileName = uploadJar(inputStream, notifier.getName());
    notifier.setJarFileName(jarFileName);
    Notifier newNotifier = catalogService.addOrUpdateNotifierInfo(id, notifier);
    return WSUtils.respondEntity(newNotifier, CREATED);
}
Also used : UnsupportedMediaTypeException(com.hortonworks.streamline.common.exception.service.exception.request.UnsupportedMediaTypeException) MediaType(javax.ws.rs.core.MediaType) Notifier(com.hortonworks.streamline.streams.catalog.Notifier) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 4 with UnsupportedMediaTypeException

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

the class NotifierInfoCatalogResource method addNotifier.

/**
 * Sample request :
 * <pre>
 * curl -X POST 'http://localhost:8080/api/v1/catalog/notifiers' -F notifierJarFile=/tmp/email-notifier.jar
 * -F notifierConfig='{
 *  "name":"email_notifier",
 *  "description": "testing",
 * "className":"com.hortonworks.streamline.streams.notifiers.EmailNotifier",
 *   "properties": {
 *     "username": "hwemailtest@gmail.com",
 *     "password": "testing12",
 *     "host": "smtp.gmail.com",
 *     "port": "587",
 *     "starttls": "true",
 *     "debug": "true"
 *     },
 *   "fieldValues": {
 *     "from": "hwemailtest@gmail.com",
 *     "to": "hwemailtest@gmail.com",
 *     "subject": "Testing email notifications",
 *     "contentType": "text/plain",
 *     "body": "default body"
 *     }
 * };type=application/json'
 * </pre>
 */
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/notifiers")
@Timed
public Response addNotifier(@FormDataParam("notifierJarFile") final InputStream inputStream, @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader, @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig, @Context SecurityContext securityContext) throws IOException {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_NOTIFIER_ADMIN);
    MediaType mediaType = notifierConfig.getMediaType();
    LOG.debug("Media type {}", mediaType);
    if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
        throw new UnsupportedMediaTypeException(mediaType.toString());
    }
    Notifier notifier = notifierConfig.getValueAs(Notifier.class);
    Collection<Notifier> existing = null;
    existing = catalogService.listNotifierInfos(Collections.singletonList(new QueryParam(Notifier.NOTIFIER_NAME, notifier.getName())));
    if (existing != null && !existing.isEmpty()) {
        LOG.warn("Received a post request for an already registered notifier. Not creating entity for " + notifier);
        return WSUtils.respondEntity(notifier, CONFLICT);
    }
    String jarFileName = uploadJar(inputStream, notifier.getName());
    notifier.setJarFileName(jarFileName);
    Notifier createdNotifier = catalogService.addNotifierInfo(notifier);
    SecurityUtil.addAcl(authorizer, securityContext, Notifier.NAMESPACE, createdNotifier.getId(), EnumSet.allOf(Permission.class));
    return WSUtils.respondEntity(createdNotifier, CREATED);
}
Also used : UnsupportedMediaTypeException(com.hortonworks.streamline.common.exception.service.exception.request.UnsupportedMediaTypeException) QueryParam(com.hortonworks.registries.common.QueryParam) Permission(com.hortonworks.streamline.streams.security.Permission) MediaType(javax.ws.rs.core.MediaType) Notifier(com.hortonworks.streamline.streams.catalog.Notifier) 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 UnsupportedMediaTypeException (com.hortonworks.streamline.common.exception.service.exception.request.UnsupportedMediaTypeException)4 Consumes (javax.ws.rs.Consumes)4 Path (javax.ws.rs.Path)4 MediaType (javax.ws.rs.core.MediaType)4 Notifier (com.hortonworks.streamline.streams.catalog.Notifier)2 UDF (com.hortonworks.streamline.streams.catalog.UDF)2 Permission (com.hortonworks.streamline.streams.security.Permission)2 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 QueryParam (com.hortonworks.registries.common.QueryParam)1