Search in sources :

Example 1 with Notifier

use of com.hortonworks.streamline.streams.catalog.Notifier in project streamline by hortonworks.

the class RestIntegrationTest method createNotifierInfo.

private Notifier createNotifierInfo(Long id, String name) {
    Notifier notifier = new Notifier();
    notifier.setClassName("A.B.C");
    notifier.setId(id);
    notifier.setJarFileName(name);
    notifier.setName(name);
    return notifier;
}
Also used : Notifier(com.hortonworks.streamline.streams.catalog.Notifier)

Example 2 with Notifier

use of com.hortonworks.streamline.streams.catalog.Notifier in project streamline by hortonworks.

the class StreamCatalogService method getNotifierInfo.

public Notifier getNotifierInfo(Long id) {
    Notifier notifier = new Notifier();
    notifier.setId(id);
    return this.dao.get(new StorableKey(NOTIFIER_INFO_NAMESPACE, notifier.getPrimaryKey()));
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) Notifier(com.hortonworks.streamline.streams.catalog.Notifier)

Example 3 with Notifier

use of com.hortonworks.streamline.streams.catalog.Notifier in project streamline by hortonworks.

the class NotifierInfoCatalogResource method downloadNotifier.

/**
 * 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());
}
Also used : StreamingOutput(javax.ws.rs.core.StreamingOutput) Notifier(com.hortonworks.streamline.streams.catalog.Notifier) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 4 with Notifier

use of com.hortonworks.streamline.streams.catalog.Notifier in project streamline by hortonworks.

the class NotifierInfoCatalogResource method removeNotifierInfo.

@DELETE
@Path("/notifiers/{id}")
@Timed
public Response removeNotifierInfo(@PathParam("id") Long id, @Context SecurityContext securityContext) {
    SecurityUtil.checkPermissions(authorizer, securityContext, Notifier.NAMESPACE, id, DELETE);
    Notifier removedNotifier = catalogService.removeNotifierInfo(id);
    if (removedNotifier != null) {
        SecurityUtil.removeAcl(authorizer, securityContext, Notifier.NAMESPACE, id);
        return WSUtils.respondEntity(removedNotifier, OK);
    }
    throw EntityNotFoundException.byId(id.toString());
}
Also used : Notifier(com.hortonworks.streamline.streams.catalog.Notifier) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) DELETE(com.hortonworks.streamline.streams.security.Permission.DELETE) Timed(com.codahale.metrics.annotation.Timed)

Example 5 with Notifier

use of com.hortonworks.streamline.streams.catalog.Notifier 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)

Aggregations

Notifier (com.hortonworks.streamline.streams.catalog.Notifier)12 Timed (com.codahale.metrics.annotation.Timed)5 Path (javax.ws.rs.Path)5 Expectations (mockit.Expectations)3 Test (org.junit.Test)3 QueryParam (com.hortonworks.registries.common.QueryParam)2 StorableKey (com.hortonworks.registries.storage.StorableKey)2 UnsupportedMediaTypeException (com.hortonworks.streamline.common.exception.service.exception.request.UnsupportedMediaTypeException)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 MediaType (javax.ws.rs.core.MediaType)2 CollectionResponse (com.hortonworks.streamline.common.CollectionResponse)1 Permission (com.hortonworks.streamline.streams.security.Permission)1 DELETE (com.hortonworks.streamline.streams.security.Permission.DELETE)1 DELETE (javax.ws.rs.DELETE)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