public Notifier addNotifierInfo(Notifier notifier) { if (notifier.getId() == null) { notifier.setId(this.dao.nextId(NOTIFIER_INFO_NAMESPACE)); } if (notifier.getTimestamp() == null) { notifier.setTimestamp(System.currentTimeMillis()); } if (StringUtils.isEmpty(notifier.getName())) { throw new StorageException("Notifier name empty"); } this.dao.add(notifier); return notifier; }
@Override public Storable fromMap(Map<String, Object> map) { this.setName((String) map.get(NOTIFIER_NAME)); this.setDescription((String) map.get(DESCRIPTION)); this.setId((Long) map.get(ID)); this.setJarFileName((String) map.get(JARFILE_NAME)); this.setClassName((String) map.get(CLASS_NAME)); this.setTimestamp((Long) map.get(TIMESTAMP)); this.setBuiltin(Boolean.valueOf((String) map.get(BUILTIN))); try { this.setProperties(this.getStringAsMap((String) map.get(PROPERTIES))); this.setFieldValues(this.getStringAsMap((String) map.get(FIELD_VALUES))); } catch (IOException e) { throw new RuntimeException(e); } return this; }
public Notifier getNotifierInfo(Long id) { Notifier notifier = new Notifier(); notifier.setId(id); return this.dao.get(new StorableKey(NOTIFIER_INFO_NAMESPACE, notifier.getPrimaryKey())); }
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);
@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); }
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()); } }
@Override public Map<String, Object> toMap() { Map<String, Object> result = super.toMap(); try { result.put(PROPERTIES, this.getMapAsString(properties)); result.put(FIELD_VALUES, this.getMapAsString(fieldValues)); result.put(BUILTIN, builtin.toString()); } catch (JsonProcessingException e) { throw new RuntimeException(e); } return result; }
/** * 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()); }
public Notifier removeNotifierInfo(Long notifierId) { Notifier notifier = new Notifier(); notifier.setId(notifierId); return dao.remove(new StorableKey(NOTIFIER_INFO_NAMESPACE, notifier.getPrimaryKey())); }