Search in sources :

Example 6 with Notifier

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

the class NotifierInfoCatalogResource method getNotifierById.

@GET
@Path("/notifiers/{id}")
@Timed
public Response getNotifierById(@PathParam("id") Long id, @Context SecurityContext securityContext) {
    boolean notifierUser = SecurityUtil.hasRole(authorizer, securityContext, Roles.ROLE_NOTIFIER_USER);
    if (notifierUser) {
        LOG.debug("Allowing get Notifier, since user has role: {}", Roles.ROLE_NOTIFIER_USER);
    } else {
        SecurityUtil.checkPermissions(authorizer, securityContext, Notifier.NAMESPACE, id, READ);
    }
    Notifier result = catalogService.getNotifierInfo(id);
    if (result != null) {
        return WSUtils.respondEntity(result, OK);
    }
    throw EntityNotFoundException.byId(id.toString());
}
Also used : Notifier(com.hortonworks.streamline.streams.catalog.Notifier) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 7 with Notifier

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

the class NotifierInfoCatalogResourceTest method testAddNotifier.

@Test
public void testAddNotifier() throws Exception {
    final Notifier notifier = new Notifier();
    notifier.setName("test");
    new Expectations() {

        {
            mockCatalogService.addNotifierInfo(notifier);
            times = 1;
            result = notifier;
            mockFormDataBodyPart.getMediaType();
            result = APPLICATION_JSON_TYPE;
            mockFormDataBodyPart.getValueAs(Notifier.class);
            result = notifier;
            mockFileStorage.upload(mockInputStream, anyString);
            result = "uploadedPath";
        }
    };
    Notifier result = (Notifier) resource.addNotifier(mockInputStream, mockFormDataContentDisposition, mockFormDataBodyPart, securityContext).getEntity();
    assertEquals(notifier, result);
}
Also used : Expectations(mockit.Expectations) Notifier(com.hortonworks.streamline.streams.catalog.Notifier) Test(org.junit.Test)

Example 8 with Notifier

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

the class NotifierInfoCatalogResourceTest method testListNotifiers.

@Test
public void testListNotifiers() {
    final Notifier notifier = new Notifier();
    final QueryParam expectedQp = new QueryParam("notifierName", "email_notifier_1");
    multiValuedMap.putSingle("notifierName", "email_notifier_1");
    new Expectations() {

        {
            mockUriInfo.getQueryParameters();
            times = 1;
            result = multiValuedMap;
            mockCatalogService.listNotifierInfos(Arrays.asList(expectedQp));
            times = 1;
            result = Arrays.asList(notifier);
        }
    };
    CollectionResponse collectionResponse = (CollectionResponse) resource.listNotifiers(mockUriInfo, securityContext).getEntity();
    assertEquals(1, collectionResponse.getEntities().size());
    assertEquals(notifier, collectionResponse.getEntities().iterator().next());
}
Also used : Expectations(mockit.Expectations) QueryParam(com.hortonworks.registries.common.QueryParam) CollectionResponse(com.hortonworks.streamline.common.CollectionResponse) Notifier(com.hortonworks.streamline.streams.catalog.Notifier) Test(org.junit.Test)

Example 9 with Notifier

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

Example 10 with Notifier

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

the class StreamCatalogService method updateNotifierJarFileName.

private void updateNotifierJarFileName(TopologySink sink) {
    String notifierClassName = sink.getConfig().getString(Notifier.CLASS_NAME, "");
    if (!notifierClassName.isEmpty()) {
        Collection<Notifier> notifiers = listNotifierInfos(QueryParam.params(Notifier.CLASS_NAME, notifierClassName));
        if (notifiers.isEmpty()) {
            throw new IllegalStateException("No registered notifier in the cluster for class '" + notifierClassName + "'");
        }
        Notifier current = notifiers.iterator().next();
        sink.getConfig().setAny(Notifier.JARFILE_NAME, current.getJarFileName());
    }
}
Also used : Notifier(com.hortonworks.streamline.streams.catalog.Notifier)

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