Search in sources :

Example 1 with EndpointMapper

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();
    }
}
Also used : ConfigurationNotValidException(org.carapaceproxy.server.config.ConfigurationNotValidException) PropertiesConfigurationStore(org.carapaceproxy.configstore.PropertiesConfigurationStore) ConfigurationStore(org.carapaceproxy.configstore.ConfigurationStore) HerdDBConfigurationStore(org.carapaceproxy.configstore.HerdDBConfigurationStore) EndpointMapper(org.carapaceproxy.server.mapper.EndpointMapper) UserRealm(org.carapaceproxy.user.UserRealm) SimpleUserRealm(org.carapaceproxy.user.SimpleUserRealm) ConfigurationChangeInProgressException(org.carapaceproxy.server.config.ConfigurationChangeInProgressException) BackendConfiguration(org.carapaceproxy.server.config.BackendConfiguration)

Example 2 with EndpointMapper

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);
    }
}
Also used : ConfigurationNotValidException(org.carapaceproxy.server.config.ConfigurationNotValidException) EndpointMapper(org.carapaceproxy.server.mapper.EndpointMapper) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ConfigurationNotValidException (org.carapaceproxy.server.config.ConfigurationNotValidException)2 EndpointMapper (org.carapaceproxy.server.mapper.EndpointMapper)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ConfigurationStore (org.carapaceproxy.configstore.ConfigurationStore)1 HerdDBConfigurationStore (org.carapaceproxy.configstore.HerdDBConfigurationStore)1 PropertiesConfigurationStore (org.carapaceproxy.configstore.PropertiesConfigurationStore)1 BackendConfiguration (org.carapaceproxy.server.config.BackendConfiguration)1 ConfigurationChangeInProgressException (org.carapaceproxy.server.config.ConfigurationChangeInProgressException)1 SimpleUserRealm (org.carapaceproxy.user.SimpleUserRealm)1 UserRealm (org.carapaceproxy.user.UserRealm)1