Search in sources :

Example 1 with ConfigKey

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;
}
Also used : ConfigKey(com.yahoo.vespa.config.ConfigKey) ConfigInstance(com.yahoo.config.ConfigInstance)

Example 2 with ConfigKey

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;
}
Also used : UserConfigRepo(com.yahoo.config.model.producer.UserConfigRepo) ConfigKey(com.yahoo.vespa.config.ConfigKey) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey)

Example 3 with ConfigKey

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);
}
Also used : ConfigKey(com.yahoo.vespa.config.ConfigKey) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) TenantName(com.yahoo.config.provision.TenantName) ApplicationInfo(com.yahoo.config.model.api.ApplicationInfo) ApplicationId(com.yahoo.config.provision.ApplicationId)

Example 4 with ConfigKey

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

Example 5 with ConfigKey

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());
}
Also used : ConfigKey(com.yahoo.vespa.config.ConfigKey) RequestHandler(com.yahoo.vespa.config.server.RequestHandler) ApplicationId(com.yahoo.config.provision.ApplicationId)

Aggregations

ConfigKey (com.yahoo.vespa.config.ConfigKey)23 Test (org.junit.Test)9 ApplicationId (com.yahoo.config.provision.ApplicationId)4 MockRequestHandler (com.yahoo.vespa.config.server.rpc.MockRequestHandler)4 Before (org.junit.Before)4 ConfigInstance (com.yahoo.config.ConfigInstance)3 ComponentId (com.yahoo.component.ComponentId)2 Version (com.yahoo.component.Version)2 ComponentClass (com.yahoo.component.provider.ComponentClass)2 TenantName (com.yahoo.config.provision.TenantName)2 HttpResponse (com.yahoo.container.jdisc.HttpResponse)2 RequestHandler (com.yahoo.vespa.config.server.RequestHandler)2 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)2 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)2 Tenants (com.yahoo.vespa.config.server.tenant.Tenants)2 File (java.io.File)2 LbServicesConfig (com.yahoo.cloud.config.LbServicesConfig)1 RoutingConfig (com.yahoo.cloud.config.RoutingConfig)1 ConfigurationRuntimeException (com.yahoo.config.ConfigurationRuntimeException)1 IntConfig (com.yahoo.config.core.IntConfig)1