use of org.carapaceproxy.server.mapper.EndpointMapper in project carapaceproxy by diennea.
the class HttpProxyServer method applyDynamicConfiguration.
private void applyDynamicConfiguration(ConfigurationStore newConfigurationStore, boolean atBoot) throws InterruptedException, ConfigurationChangeInProgressException {
if (atBoot && newConfigurationStore != null) {
throw new IllegalStateException();
}
if (!atBoot && newConfigurationStore == null) {
throw new IllegalStateException();
}
// at boot we are constructing a configuration from the database
// if the system is already "up" we have to only apply the new config
ConfigurationStore storeWithConfig = atBoot ? dynamicConfigurationStore : newConfigurationStore;
if (!configurationLock.tryLock()) {
throw new ConfigurationChangeInProgressException();
}
try {
RuntimeServerConfiguration newConfiguration = buildValidConfiguration(storeWithConfig);
EndpointMapper newMapper = buildMapper(newConfiguration.getMapperClassname(), storeWithConfig);
newMapper.setParent(this);
UserRealm newRealm = buildRealm(userRealmClassname, storeWithConfig);
this.filters = buildFilters(newConfiguration);
this.backendHealthManager.reloadConfiguration(newConfiguration, newMapper);
this.dynamicCertificatesManager.reloadConfiguration(newConfiguration);
this.ocspStaplingManager.reloadConfiguration(newConfiguration);
this.listeners.reloadConfiguration(newConfiguration);
this.cache.reloadConfiguration(newConfiguration);
this.requestsLogger.reloadConfiguration(newConfiguration);
this.realm = newRealm;
Map<String, BackendConfiguration> currentBackends = mapper != null ? mapper.getBackends() : Collections.emptyMap();
Map<String, BackendConfiguration> newBackends = newMapper.getBackends();
this.mapper = newMapper;
if (atBoot || !newBackends.equals(currentBackends) || isConnectionsConfigurationChanged(newConfiguration)) {
prometheusRegistry.clear();
Metrics.globalRegistry.clear();
proxyRequestsManager.reloadConfiguration(newConfiguration, newBackends.values());
}
if (!atBoot) {
dynamicConfigurationStore.commitConfiguration(newConfigurationStore);
}
this.currentConfiguration = newConfiguration;
} catch (ConfigurationNotValidException err) {
// impossible to have a non valid configuration here
throw new IllegalStateException(err);
} finally {
configurationLock.unlock();
}
}
use of org.carapaceproxy.server.mapper.EndpointMapper in project carapaceproxy by diennea.
the class HttpProxyServer method buildMapper.
private static EndpointMapper buildMapper(String className, ConfigurationStore properties) throws ConfigurationNotValidException {
try {
EndpointMapper res = (EndpointMapper) Class.forName(className).getConstructor().newInstance();
res.configure(properties);
return res;
} catch (ClassNotFoundException err) {
throw new ConfigurationNotValidException(err);
} catch (IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | SecurityException | InvocationTargetException err) {
throw new RuntimeException(err);
}
}
Aggregations