use of com.peterphi.std.guice.config.rest.types.ConfigPropertyData in project stdlib by petergeneric.
the class NetworkConfigReloadDaemon method reload.
/**
* Called to initiate an intelligent reload of a particular config
*
* @param config
*/
void reload(NetworkConfig config) {
try {
log.trace("Load config data from " + config.path + " into " + config);
final ConfigPropertyData read = configService.read(config.path, configInstanceId, config.getLastRevision());
// Abort if the server returns no config - we have the latest revision
if (read == null || read.properties == null || read.properties.isEmpty())
return;
for (ConfigPropertyValue property : read.properties) {
config.properties.set(property.getName(), property.getValue());
}
config.setLastRevision(read.revision);
} catch (Throwable t) {
log.warn("Error loading config from path " + config.path, t);
}
}
use of com.peterphi.std.guice.config.rest.types.ConfigPropertyData in project stdlib by petergeneric.
the class GuiceFactory method applyNetworkConfiguration.
/**
* Add to the configuration any properties defined by the network configuration endpoint (if network config is enabled in a
* previous property)
*
* @param config
*/
private static void applyNetworkConfiguration(final GuiceConfig config) {
final String configEndpoint = config.get(GuiceProperties.CONFIG_ENDPOINT, null);
final Boolean configSkip = config.getBoolean(GuiceProperties.CONFIG_SKIP, false);
if (configEndpoint != null && !configSkip) {
final boolean useMoxy = config.getBoolean(GuiceProperties.MOXY_ENABLED, true);
final JAXBContextResolver jaxb = new JAXBContextResolver(new JAXBSerialiserFactory(useMoxy));
final ResteasyClientFactoryImpl clientFactory = new ResteasyClientFactoryImpl(null, null, null, jaxb);
try {
final ResteasyProxyClientFactoryImpl proxyFactory = new ResteasyProxyClientFactoryImpl(clientFactory, config);
final ConfigRestService client = proxyFactory.getClient(ConfigRestService.class);
// We set it in the config because otherwise the NetworkConfigReloadDaemon won't be able to load the config
if (config.get(GuiceProperties.CONFIG_PATH) == null) {
config.set(GuiceProperties.CONFIG_PATH, "services/" + config.get(GuiceProperties.SERVLET_CONTEXT_NAME, "unknown-service"));
}
// Get the config path to read
final String path = config.get(GuiceProperties.CONFIG_PATH);
final ConfigPropertyData data = client.read(path, config.get(GuiceProperties.INSTANCE_ID), null);
for (ConfigPropertyValue property : data.properties) {
config.set(property.name, property.value);
}
// Let others know that the configuration data is coming from a network source
config.set(GuiceProperties.CONFIG_SOURCE, GuiceConstants.CONFIG_SOURCE_NETWORK);
if (data.revision != null)
config.set(GuiceProperties.CONFIG_REVISION, data.revision);
} finally {
clientFactory.shutdown();
}
} else {
// Config is not coming from the network
config.set(GuiceProperties.CONFIG_SOURCE, GuiceConstants.CONFIG_SOURCE_LOCAL);
}
}
use of com.peterphi.std.guice.config.rest.types.ConfigPropertyData in project stdlib by petergeneric.
the class ConfigUIServiceImpl method getConfigPage.
@Override
public String getConfigPage(final String path) {
final ConfigPropertyData config = repo.get(REF, path);
final List<String> paths = repo.getPaths(REF);
final List<ConfigPropertyValue> inheritedProperties;
final List<ConfigPropertyValue> definedProperties;
{
// Sort alphabetically for the UI
config.properties.sort(Comparator.comparing(ConfigPropertyValue::getName));
inheritedProperties = computeInheritedProperties(config);
definedProperties = computeDefinedProperties(config);
}
final TemplateCall call = templater.template("config-edit");
call.set("nonce", nonceStore.getValue(NONCE_USE));
call.set("repo", repo);
call.set("config", config);
call.set("inheritedProperties", inheritedProperties);
call.set("definedProperties", definedProperties);
call.set("path", config.path);
call.set("paths", paths);
call.set("children", getChildren(config.path, paths));
call.set("parent", getParent(config.path));
return call.process();
}
use of com.peterphi.std.guice.config.rest.types.ConfigPropertyData in project stdlib by petergeneric.
the class RepoHelper method read.
private static ConfigPropertyData read(final Repository repo, final RevCommit commit, final String path) throws IOException {
ConfigPropertyData data = new ConfigPropertyData();
data.timestamp = new Date(1000L * commit.getCommitTime());
data.path = normalisePath(path);
data.revision = commit.getId().getName();
data.properties = readProperties(repo, commit, path);
return data;
}
Aggregations