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());
}
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);
}
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());
}
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);
}
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());
}
}
Aggregations