private void addConfigSource(ConfigSource source) { LOGGER.finest(() -> "Adding config source: " + source.getName() + " (" + source.getClass() .getName() + "), values: " + source.getProperties()); mpConfigSources.add(source); helidonConfigSources.add(wrapSource(source)); }
/** * Get all properties of this config as a map. * * @return map where keys are configuration keys and values are associated string values */ public Map<String, String> asMap() { // config from helidon config instance Map<String, String> map = new HashMap<>(config.get().asMap().get()); // now add all properties from sources of MP config List<ConfigSource> configSources = new ArrayList<>(mpConfigSources); Collections.reverse(configSources); for (ConfigSource configSource : configSources) { map.putAll(configSource.getProperties()); } return map; }
private OrdinalConfigSource wrapSource(ConfigSource source) { io.helidon.config.spi.ConfigSource myCs = ConfigSources.create(source.getProperties()).build(); return new OrdinalConfigSource(myCs, source.getOrdinal()); }
/** * Gets all property names known to this config source, without evaluating the values. * * For backwards compatibility, there is a default implementation that just returns the keys of {@code getProperties()} * slower ConfigSource implementations should replace this with a more performant implementation * * @return the set of property keys that are known to this ConfigSource */ default Set<String> getPropertyNames() { return getProperties().keySet(); }
@Override public Iterable<String> getPropertyNames() { Set<String> names = new HashSet<>(); for (ConfigSource configSource : configSources) { names.addAll(configSource.getProperties().keySet()); } return names; }
private void addConfigSource(ConfigSource source) { LOGGER.finest(() -> "Adding config source: " + source.getName() + " (" + source.getClass() .getName() + "), values: " + source.getProperties()); mpConfigSources.add(source); helidonConfigSources.add(wrapSource(source)); }
@DELETE @Path("/key/{key}") @Operation(description = "Remove the value in the Memory config source") @APIResponse(responseCode = "202", description = "Accepted the key, value removed") public Response removeValue(@Parameter(name = "key", description = "The key for this config", required = true, allowEmptyValue = false, example = "some.key") @PathParam("key") String key) { if(!enabled)return Response.status(Response.Status.FORBIDDEN).header(REASON, NOT_ENABLED).build(); Map<String,String> before = new HashMap<>(memoryConfigSource.getProperties()); memoryConfigSource.getProperties().remove(key); Map<String,String> after = new HashMap<>(memoryConfigSource.getProperties()); if(notifyOnChange)ChangeEventNotifier.getInstance().detectChangesAndFire(before, after,MemoryConfigSource.NAME); return Response.accepted().build(); }
private Response allForConfigSourceToJson(String configsource) { if(configSourceMap.containsKey(configsource)){ ConfigSource source = configSourceMap.get(configsource); Set<Map.Entry<String, String>> propertiesSet = source.getProperties().entrySet(); JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); for(Map.Entry<String, String> propertyEntry:propertiesSet){ arrayBuilder.add(Json.createObjectBuilder().add(propertyEntry.getKey(), propertyEntry.getValue()).build()); } return Response.ok(arrayBuilder.build()).build(); } return Response.noContent().header(REASON, NO_SUCH_CONFIGSOURCE).build(); }
/** * Get all properties of this config as a map. * * @return map where keys are configuration keys and values are associated string values */ public Map<String, String> asMap() { // config from helidon config instance Map<String, String> map = new HashMap<>(config.get().asMap().get()); // now add all properties from sources of MP config List<ConfigSource> configSources = new ArrayList<>(mpConfigSources); Collections.reverse(configSources); for (ConfigSource configSource : configSources) { map.putAll(configSource.getProperties()); } return map; }
@DELETE @Path("/key/{key}") @Operation(description = "Remove the value in the Memory config source") @APIResponse(responseCode = "202", description = "Accepted the key, value removed") public Response removeValue(@NotNull @Parameter(name = "key", description = "The key for this config", required = true, allowEmptyValue = false, example = "some.key") @PathParam("key") String key) { memoryConfigSource.getProperties().remove(key); return Response.accepted().build(); }
@PUT @Path("/key/{key}") @Operation(description = "Change or add a new key") @APIResponse(responseCode = "202", description = "Accepted the key, value updated") @Consumes(MediaType.TEXT_PLAIN) public Response setValue(@Parameter(name = "key", description = "The key for this config", required = true, allowEmptyValue = false, example = "some.key") @PathParam("key") String key, @RequestBody(description = "Value for this key") String value) { if(!enabled)return Response.status(Response.Status.FORBIDDEN).header(REASON, NOT_ENABLED).build(); Map<String,String> before = new HashMap<>(memoryConfigSource.getProperties()); memoryConfigSource.getProperties().put(key, value); Map<String,String> after = new HashMap<>(memoryConfigSource.getProperties()); if(notifyOnChange)ChangeEventNotifier.getInstance().detectChangesAndFire(before, after,MemoryConfigSource.NAME); return Response.accepted().build(); }
@PUT @Path("/key/{key}") @Operation(description = "Change or add a new key") @APIResponse(responseCode = "202", description = "Accepted the key, value updated") @Consumes(MediaType.TEXT_PLAIN) public Response setValue(@NotNull @Parameter(name = "key", description = "The key for this config", required = true, allowEmptyValue = false, example = "some.key") @PathParam("key") String key, @RequestBody(description = "Value for this key") String value) { memoryConfigSource.getProperties().put(key, value); return Response.accepted().build(); }
private OrdinalConfigSource wrapSource(ConfigSource source) { io.helidon.config.spi.ConfigSource myCs = ConfigSources.create(source.getProperties()).build(); return new OrdinalConfigSource(myCs, source.getOrdinal()); }