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."));
}
}
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;
}
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());
}
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;
}
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");
}
}
Aggregations