public void deletePodLogState(String podName) throws IOException { jsonDB.delete("/logs/pods/" + podName); }
/** * Creates or Replaces the object or value at the given path * with the supplied json document. * * @param path to the object or value to set * @param json value to set it to, can be a json primitive or struct */ default void set(String path, String json) { set(path, json.getBytes(StandardCharsets.UTF_8)); }
/** * @param path to the object or value to set * @param json value to set it to, can be a json primitive or struct */ default void update(String path, String json) { update(path, json.getBytes(StandardCharsets.UTF_8)); }
/** * Persists the latest metrics of a live pod to the database. */ @Override public void persist(RawMetrics rawMetrics) { try { //persist the latest rawMetrics String path = path(rawMetrics.getIntegrationId(), rawMetrics.getPod()); String json = Json.writer().writeValueAsString(rawMetrics); if (jsonDB.exists(path)) { //only update if not the same (don't cause unnecessary and expensive writes) if (! jsonDB.getAsString(path).equals(json)) { jsonDB.update(path, json); } } else { jsonDB.set(path, json); } } catch (JsonProcessingException e) { LOGGER.error("Error persisting metrics!", e); } }
@Override public T create(T entity) { try { String dbPath = getCollectionPath()+"/:"+entity.getId().get(); // Only create if it did not exist. if( jsondb.exists(dbPath) ) { return null; } byte[] json = Json.mapper().writeValueAsBytes(entity); jsondb.set(dbPath, json); return entity; } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException|IOException e) { throw SyndesisServerException.launderThrowable(e); } }
default byte[] getAsByteArray(String path) { return getAsByteArray(path, null); }
/** * If Integrations get deleted we should also delete their metrics * * @param activeIntegrationIds * @throws IOException * @throws JsonMappingException */ @Override public void curate(Set<String> activeIntegrationIds) throws IOException, JsonMappingException { //1. Loop over all RawMetrics String json = jsonDB.getAsString(path(), new GetOptions().depth(1)); if (json != null) { Map<String,Boolean> metricsMap = Json.reader().forType(TYPE_REFERENCE).readValue(json); Set<String> rawIntegrationIds = metricsMap.keySet(); for (String rawIntId : rawIntegrationIds) { if (! activeIntegrationIds.contains(rawIntId)) { jsonDB.delete(path(rawIntId)); } } } }
options.prettyPrint(true); } else if ("silent".equals(print)) { if( jsondb.exists(path) ) { return Response.noContent().build(); Consumer<OutputStream> stream = jsondb.getAsStreamingOutput(path, options); if( stream == null ) { return Response.status(Response.Status.NOT_FOUND).build();
/** * Same as {@code getAsString(path, null)} */ default String getAsString(String path) { return getAsString(path, null); }
/** * Pushes a new value to the the requested path. * Same as: {@code set( path + "/" + createKey(), json)} * * @param path to the object or value to set * @param json value to set it to, can be a json primitive or struct * @return the field name that was added to the path object */ default String push(String path, String json) { return push(path, json.getBytes(StandardCharsets.UTF_8)); }
default void getAsStream(String path, OutputStream os) { getAsStream(path, null, os); }
default Consumer<OutputStream> getAsStreamingOutput(String path) { return getAsStreamingOutput(path, null); }
@Override public Set<String> fetchIdsByPropertyValue(final String property, final String propertyValue) { return jsondb.fetchIdsByPropertyValue(getCollectionPath(), property.replace('.', '/'), propertyValue) .stream().map(path -> path.substring(path.indexOf(':') + 1)).collect(Collectors.toSet()); }
@Override public T create(T entity) { try { String dbPath = getCollectionPath()+"/:"+entity.getId().get(); // Only create if it did not exist. if( jsondb.exists(dbPath) ) { return null; } byte[] json = Json.writer().writeValueAsBytes(entity); jsondb.set(dbPath, json); return entity; } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException|IOException e) { throw SyndesisServerException.launderThrowable(e); } }
default byte[] getAsByteArray(String path) { return getAsByteArray(path, null); }
options.prettyPrint(true); } else if ("silent".equals(print)) { if( jsondb.exists(path) ) { return Response.noContent().build(); Consumer<OutputStream> stream = jsondb.getAsStreamingOutput(path, options); if( stream == null ) { return Response.status(Response.Status.NOT_FOUND).build();
/** * Same as {@code getAsString(path, null)} */ default String getAsString(String path) { return getAsString(path, null); }
/** * Pushes a new value to the the requested path. * Same as: {@code set( path + "/" + createKey(), json)} * * @param path to the object or value to set * @param json value to set it to, can be a json primitive or struct * @return the field name that was added to the path object */ default String push(String path, String json) { return push(path, json.getBytes(StandardCharsets.UTF_8)); }
default void getAsStream(String path, OutputStream os) { getAsStream(path, null, os); }