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)); }
@Override public int compare(ConfigSource o1, ConfigSource o2) { int v1 = o1.getOrdinal(); int v2 = o2.getOrdinal(); if ( v1 > v2 ) { return -11; } if ( v1 < v2 ) { return +1; } // if 2 config sources have the same ordinal, // provide consistent order by sorting them // according to their name. if (o2.getName() != null && o1.getName() != null) { return o2.getName().compareTo(o1.getName()); } return 0; } });
private ConfigSource getMemoryConfigSource() { for(ConfigSource configSource:config.getConfigSources()){ if(configSource.getName().equals(MemoryConfigSource.NAME))return configSource; } return null; }
public String getValue(String key) { for (ConfigSource configSource : configSources) { String value = configSource.getValue(key); if (value != null) { if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "found value {0} for key {1} in ConfigSource {2}.", new Object[]{value, key, configSource.getName()}); } return value; } } return null; }
/** * ConfigSources are sorted with descending ordinal. * If 2 ConfigSources have the same ordinal, then they get sorted according to their name, alphabetically. */ private List<ConfigSource> sortDescending(List<ConfigSource> configSources) { configSources.sort( (configSource1, configSource2) -> { int compare = Integer.compare(configSource2.getOrdinal(), configSource1.getOrdinal()); if (compare == 0) { return configSource1.getName().compareTo(configSource2.getName()); } return compare; }); return configSources; }
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)); }
private JsonObject toJsonObject(ConfigSource source){ return Json.createObjectBuilder().add(String.valueOf(source.getOrdinal()), source.getName()).build(); }
private String getPropertyValue(String key,String defaultValue){ Config config = ConfigProvider.getConfig(); Iterable<ConfigSource> configSources = config.getConfigSources(); for(ConfigSource configsource:configSources){ if(!configsource.getName().equals(NAME)){ String val = configsource.getValue(key); if(val!=null && !val.isEmpty())return val; } } return defaultValue; }
@GET @Path("/sources") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Getting all the current config sources") @APIResponse(responseCode = "200", description = "Successfull, returning the config sources in JSON format") public Response getConfigSources(){ JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); for(ConfigSource source:config.getConfigSources()){ arrayBuilder.add(Json.createObjectBuilder().add(String.valueOf(source.getOrdinal()), source.getName()).build()); } return Response.ok(arrayBuilder.build()).build(); }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { super.performRuntime(context, operation, model); String name = context.getCurrentAddressValue(); int ordinal = ORDINAL.resolveModelAttribute(context, model).asInt(); ModelNode props = PROPERTIES.resolveModelAttribute(context, model); ModelNode classModel = CLASS.resolveModelAttribute(context, model); ModelNode dirModel = DIR.resolveModelAttribute(context, model); final ConfigSource configSource; if (classModel.isDefined()) { Class configSourceClass = unwrapClass(classModel); try { configSource = ConfigSource.class.cast(configSourceClass.newInstance()); } catch (Exception e) { throw new OperationFailedException(e); } } else if (dirModel.isDefined()) { File dir = new File(dirModel.asString()); configSource = new DirConfigSource(dir, ordinal); } else { Map<String, String> properties = PropertiesAttributeDefinition.unwrapModel(context, props); configSource = new PropertiesConfigSource(properties, name, ordinal); } MicroProfileConfigLogger.ROOT_LOGGER.info("Reading properties from " + configSource.getName()); ConfigSourceService.install(context, name, configSource); } }, new AbstractRemoveStepHandler() {