use of com.yahoo.vespa.config.ConfigKey in project vespa by vespa-engine.
the class ComponentClass method createComponent.
/**
* Create an instance of this ComponentClass with the given configId. The configs needed by the component
* must exist in the provided set of {@link com.yahoo.config.ConfigInstance}s.
*
* @param id The id of the component to create, never null.
* @param availableConfigs The set of available config instances.
* @param configId The config ID of the component, nullable.
* @return A new instance of the class represented by this ComponentClass.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public T createComponent(ComponentId id, Map<ConfigKey, ConfigInstance> availableConfigs, String configId) {
if (configId == null) {
configId = System.getProperty("config.id");
}
boolean hasId = false;
List<Object> params = new LinkedList<>();
for (Class cc : constructor.parameters) {
if (cc.equals(ComponentId.class)) {
params.add(id);
hasId = true;
} else if (cc.getSuperclass().equals(ConfigInstance.class)) {
ConfigKey key = new ConfigKey(cc, configId);
if ((availableConfigs == null) || !availableConfigs.containsKey(key)) {
throw new IllegalStateException("Could not resolve config instance '" + key + "' required to instantiate " + clazz);
}
params.add(availableConfigs.get(key));
}
}
T component = construct(params.toArray());
if (hasId && component.hasInitializedId() && !id.equals(component.getId())) {
log.warning("Component with id '" + id + "' tried to set illegal component id: '" + component.getId() + "', or the component takes ComponentId as a constructor arg without calling super(id).");
}
// Enforce correct id - see bug #4036397
component.initId(id);
return component;
}
use of com.yahoo.vespa.config.ConfigKey in project vespa by vespa-engine.
the class VespaModel method configsProduced.
private static Set<ConfigKey<?>> configsProduced(ConfigProducer cp) {
Set<ConfigKey<?>> ret = ReflectionUtil.configsProducedByInterface(cp.getClass(), cp.getConfigId());
UserConfigRepo userConfigs = cp.getUserConfigs();
for (ConfigDefinitionKey userKey : userConfigs.configsProduced()) {
ret.add(new ConfigKey<>(userKey.getName(), cp.getConfigId(), userKey.getNamespace()));
}
return ret;
}
use of com.yahoo.vespa.config.ConfigKey in project vespa by vespa-engine.
the class SuperModelConfigProvider method getConfig.
public <CONFIGTYPE extends ConfigInstance> CONFIGTYPE getConfig(Class<CONFIGTYPE> configClass, ApplicationId applicationId, String configId) {
TenantName tenant = applicationId.tenant();
if (!superModel.getAllModels().containsKey(tenant)) {
throw new IllegalArgumentException("Tenant " + tenant + " not found");
}
Map<ApplicationId, ApplicationInfo> applications = superModel.getAllModels().get(tenant);
if (!applications.containsKey(applicationId)) {
throw new IllegalArgumentException("Application id " + applicationId + " not found");
}
ApplicationInfo application = applications.get(applicationId);
ConfigKey<CONFIGTYPE> key = new ConfigKey<>(configClass, configId);
ConfigPayload payload = application.getModel().getConfig(key, null);
return payload.toInstance(configClass, configId);
}
use of com.yahoo.vespa.config.ConfigKey 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");
}
}
use of com.yahoo.vespa.config.ConfigKey in project vespa by vespa-engine.
the class HttpListConfigsHandler method handleGET.
@Override
public HttpResponse handleGET(HttpRequest req) {
HttpListConfigsRequest listReq = HttpListConfigsRequest.createFromListRequest(req);
RequestHandler requestHandler = HttpConfigRequests.getRequestHandler(tenants, listReq);
ApplicationId appId = listReq.getApplicationId();
Set<ConfigKey<?>> configs = requestHandler.listConfigs(appId, Optional.empty(), listReq.isRecursive());
String urlBase = getUrlBase(req, listReq, appId, zone);
Set<ConfigKey<?>> allConfigs = requestHandler.allConfigsProduced(appId, Optional.empty());
return new ListConfigsResponse(configs, allConfigs, urlBase, listReq.isRecursive());
}
Aggregations