com.yahoo.vespa.config.server.SuperModelRequestHandler Maven / Gradle / Ivy
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server;
import com.yahoo.component.annotation.Inject;
import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.component.Version;
import com.yahoo.config.FileReference;
import com.yahoo.config.model.api.ConfigDefinitionRepo;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.vespa.config.ConfigKey;
import com.yahoo.vespa.config.GetConfigRequest;
import com.yahoo.vespa.config.protocol.ConfigResponse;
import com.yahoo.vespa.config.server.application.ApplicationVersions;
import com.yahoo.vespa.config.server.rpc.ConfigResponseFactory;
import java.util.Optional;
import java.util.Set;
/**
* Handles request for supermodel config.
*
* @author Ulf Lilleengen
*/
public class SuperModelRequestHandler implements RequestHandler {
private volatile SuperModelController handler;
private final ConfigDefinitionRepo configDefinitionRepo;
private final ConfigResponseFactory responseFactory;
private final SuperModelManager superModelManager;
private volatile boolean enabled = false;
/**
* Creates a supermodel controller
*/
@Inject
public SuperModelRequestHandler(ConfigDefinitionRepo configDefinitionRepo,
ConfigserverConfig configserverConfig,
SuperModelManager superModelManager) {
this.configDefinitionRepo = configDefinitionRepo;
this.responseFactory = ConfigResponseFactory.create(configserverConfig);
this.superModelManager = superModelManager;
updateHandler();
}
/**
* Signals that config has been activated for an {@link com.yahoo.vespa.config.server.application.Application}
* belonging to a tenant.
*
* @param applicationVersions The activated set of {@link com.yahoo.vespa.config.server.application.Application}s.
*/
public synchronized void activateConfig(ApplicationVersions applicationVersions) {
superModelManager.configActivated(applicationVersions);
updateHandler();
}
public synchronized void removeApplication(ApplicationId applicationId) {
superModelManager.applicationRemoved(applicationId);
updateHandler();
}
private void updateHandler() {
handler = new SuperModelController(
superModelManager.getSuperModelConfigProvider(),
configDefinitionRepo,
superModelManager.getGeneration(),
responseFactory);
}
public SuperModelController getHandler() { return handler; }
@Override
public ConfigResponse resolveConfig(ApplicationId appId, GetConfigRequest req, Optional vespaVersion) {
return (handler == null) ? null : handler.resolveConfig(req);
}
@Override
public Set> listConfigs(ApplicationId appId, Optional vespaVersion, boolean recursive) {
throw new UnsupportedOperationException();
}
@Override
public Set> listNamedConfigs(ApplicationId appId, Optional vespaVersion, ConfigKey> key, boolean recursive) {
throw new UnsupportedOperationException();
}
@Override
public Set> allConfigsProduced(ApplicationId appId, Optional vespaVersion) {
throw new UnsupportedOperationException();
}
@Override
public Set allConfigIds(ApplicationId appID, Optional vespaVersion) {
throw new UnsupportedOperationException();
}
@Override
public boolean hasApplication(ApplicationId appId, Optional vespaVersion) {
return enabled && appId.equals(ApplicationId.global());
}
@Override
public ApplicationId resolveApplicationId(String hostName) {
return ApplicationId.global();
}
@Override
public Set listFileReferences(ApplicationId applicationId) {
throw new UnsupportedOperationException();
}
@Override
public boolean compatibleWith(Optional vespaVersion, ApplicationId application) {
return true;
}
public void enable() {
enabled = true;
superModelManager.markAsComplete();
updateHandler();
}
}