Search in sources :

Example 6 with ConfigurationRuntimeException

use of com.yahoo.config.ConfigurationRuntimeException in project vespa by vespa-engine.

the class DomConfigPayloadBuilderTest method testFailNoNameAttribute.

// Verifies that an exception is thrown when the root element is not 'config'.
@Test
public void testFailNoNameAttribute() throws FileNotFoundException, ParserConfigurationException {
    Element configRoot = getDocument(new StringReader("<config/>"));
    try {
        new DomConfigPayloadBuilder(null).build(configRoot);
        fail("Expected exception for mismatch between def-name and xml name attribute.");
    } catch (ConfigurationRuntimeException e) {
        assertThat(e.getMessage(), is("The 'config' element must have a 'name' attribute that matches the name of the config definition."));
    }
}
Also used : ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException) Element(org.w3c.dom.Element) Test(org.junit.Test)

Example 7 with ConfigurationRuntimeException

use of com.yahoo.config.ConfigurationRuntimeException in project vespa by vespa-engine.

the class ConfigSubscriber method subscribe.

/**
 * Use this convenience method if you only want to subscribe on <em>one</em> config, and want generic error handling.
 * Implement {@link SingleSubscriber} and pass to this method.
 * You will get initial config, and a config thread will be started. The method will throw in your thread if initial
 * configuration fails, and the config thread will print a generic error message (but continue) if it fails thereafter. The config
 * thread will stop if you {@link #close()} this {@link ConfigSubscriber}.
 *
 * @param <T> ConfigInstance type
 * @param singleSubscriber The object to receive config
 * @param configClass      The class, typically generated from a def-file using config-class-plugin
 * @param configId         Identifies the service in vespa-services.xml
 * @return The handle of the config
 * @see #startConfigThread(Runnable)
 */
public <T extends ConfigInstance> ConfigHandle<T> subscribe(final SingleSubscriber<T> singleSubscriber, Class<T> configClass, String configId) {
    if (!subscriptionHandles.isEmpty())
        throw new IllegalStateException("Can not start single-subscription because subscriptions were previously opened on this.");
    final ConfigHandle<T> handle = subscribe(configClass, configId);
    if (!nextConfig())
        throw new ConfigurationRuntimeException("Initial config of " + configClass.getName() + " failed.");
    singleSubscriber.configure(handle.getConfig());
    startConfigThread(new Runnable() {

        @Override
        public void run() {
            while (!isClosed()) {
                try {
                    if (nextConfig()) {
                        if (handle.isChanged())
                            singleSubscriber.configure(handle.getConfig());
                    }
                } catch (Exception e) {
                    log.log(LogLevel.ERROR, "Exception from config system, continuing config thread: " + Exceptions.toMessageString(e));
                }
            }
        }
    });
    return handle;
}
Also used : ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException) ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException)

Example 8 with ConfigurationRuntimeException

use of com.yahoo.config.ConfigurationRuntimeException in project vespa by vespa-engine.

the class JRTConfigRequester method handleOKRequest.

private void handleOKRequest(JRTClientConfigRequest jrtReq, JRTConfigSubscription<ConfigInstance> sub, Connection connection) {
    // Reset counters pertaining to error handling here
    fatalFailures = 0;
    transientFailures = 0;
    suspendWarningLogged = Instant.MIN;
    noApplicationWarningLogged = Instant.MIN;
    connection.setSuccess();
    sub.setLastCallBackOKTS(System.currentTimeMillis());
    if (jrtReq.hasUpdatedGeneration()) {
        // We only want this latest generation to be in the queue, we do not preserve history in this system
        sub.getReqQueue().clear();
        boolean putOK = sub.getReqQueue().offer(jrtReq);
        if (!putOK) {
            sub.setException(new ConfigurationRuntimeException("Could not put returned request on queue of subscription " + sub));
        }
    }
    if (sub.getState() != ConfigSubscription.State.OPEN)
        return;
    scheduleNextRequest(jrtReq, sub, calculateSuccessDelay(), calculateSuccessTimeout());
}
Also used : ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException)

Example 9 with ConfigurationRuntimeException

use of com.yahoo.config.ConfigurationRuntimeException in project vespa by vespa-engine.

the class JarConfigSubscription method nextConfig.

@Override
public boolean nextConfig(long timeout) {
    if (checkReloaded()) {
        // Not supporting changing the payload for jar
        return true;
    }
    if (zipEntry == null) {
        // First time polled
        JarFile jarFile = null;
        try {
            jarFile = new JarFile(jarName);
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        }
        zipEntry = getEntry(jarFile, path);
        if (zipEntry == null)
            throw new IllegalArgumentException("Config '" + key.getName() + "' not found in '" + jarName + "!/" + path + "'.");
        T config = null;
        try {
            ConfigPayload payload = new CfgConfigPayloadBuilder().deserialize(Arrays.asList(IOUtils.readAll(new InputStreamReader(jarFile.getInputStream(zipEntry), "UTF-8")).split("\n")));
            config = payload.toInstance(configClass, key.getConfigId());
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException(e);
        } catch (IOException e) {
            throw new ConfigurationRuntimeException(e);
        }
        setConfig(0L, config);
        try {
            jarFile.close();
        } catch (IOException e) {
            throw new ConfigurationRuntimeException(e);
        }
        return true;
    }
    // TODO: Should wait and detect changes
    try {
        Thread.sleep(timeout);
    } catch (InterruptedException e) {
        throw new ConfigInterruptedException(e);
    }
    return false;
}
Also used : CfgConfigPayloadBuilder(com.yahoo.config.subscription.CfgConfigPayloadBuilder) ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) InputStreamReader(java.io.InputStreamReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigInterruptedException(com.yahoo.config.subscription.ConfigInterruptedException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) ConfigInterruptedException(com.yahoo.config.subscription.ConfigInterruptedException)

Example 10 with ConfigurationRuntimeException

use of com.yahoo.config.ConfigurationRuntimeException in project vespa by vespa-engine.

the class SuperModelConfigProvider method getConfig.

public ConfigPayload getConfig(ConfigKey<?> configKey) {
    // TODO: Override not applied, but not really necessary here
    if (configKey.equals(new ConfigKey<>(LbServicesConfig.class, configKey.getConfigId()))) {
        LbServicesConfig.Builder builder = new LbServicesConfig.Builder();
        getConfig(builder);
        return ConfigPayload.fromInstance(new LbServicesConfig(builder));
    } else if (configKey.equals(new ConfigKey<>(RoutingConfig.class, configKey.getConfigId()))) {
        RoutingConfig.Builder builder = new RoutingConfig.Builder();
        getConfig(builder);
        return ConfigPayload.fromInstance(new RoutingConfig(builder));
    } else {
        throw new ConfigurationRuntimeException(configKey + " is not valid when asking for config from SuperModel");
    }
}
Also used : ConfigKey(com.yahoo.vespa.config.ConfigKey) ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException) LbServicesConfig(com.yahoo.cloud.config.LbServicesConfig) RoutingConfig(com.yahoo.cloud.config.RoutingConfig)

Aggregations

ConfigurationRuntimeException (com.yahoo.config.ConfigurationRuntimeException)15 Element (org.w3c.dom.Element)3 ConfigInstance (com.yahoo.config.ConfigInstance)2 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)2 ConfigPayloadBuilder (com.yahoo.vespa.config.ConfigPayloadBuilder)2 Test (org.junit.Test)2 LbServicesConfig (com.yahoo.cloud.config.LbServicesConfig)1 RoutingConfig (com.yahoo.cloud.config.RoutingConfig)1 ChainSpecification (com.yahoo.component.chain.model.ChainSpecification)1 ConfigBuilder (com.yahoo.config.ConfigBuilder)1 Builder (com.yahoo.config.ConfigInstance.Builder)1 CfgConfigPayloadBuilder (com.yahoo.config.subscription.CfgConfigPayloadBuilder)1 ConfigInterruptedException (com.yahoo.config.subscription.ConfigInterruptedException)1 com.yahoo.vespa.config (com.yahoo.vespa.config)1 ConfigCacheKey (com.yahoo.vespa.config.ConfigCacheKey)1 ConfigKey (com.yahoo.vespa.config.ConfigKey)1 GenericConfig (com.yahoo.vespa.config.GenericConfig)1 ConfigDefinition (com.yahoo.vespa.config.buildergen.ConfigDefinition)1 ConfigResponse (com.yahoo.vespa.config.protocol.ConfigResponse)1 UnknownConfigDefinitionException (com.yahoo.vespa.config.server.UnknownConfigDefinitionException)1