use of com.yahoo.config.provision.TenantName in project vespa by vespa-engine.
the class SuperModel method cloneAndSetApplication.
public SuperModel cloneAndSetApplication(ApplicationInfo application) {
TenantName tenant = application.getApplicationId().tenant();
Map<TenantName, Map<ApplicationId, ApplicationInfo>> newModels = cloneModels(models);
if (!newModels.containsKey(tenant)) {
// New application has been activated
newModels.put(tenant, new LinkedHashMap<>());
} else {
// Application has been redeployed
}
newModels.get(tenant).put(application.getApplicationId(), application);
return new SuperModel(newModels);
}
use of com.yahoo.config.provision.TenantName in project vespa by vespa-engine.
the class HostHandler method handleGET.
@Override
public HttpResponse handleGET(HttpRequest request) {
String hostname = getBindingMatch(request).group(2);
log.log(LogLevel.DEBUG, "hostname=" + hostname);
HostRegistry<TenantName> tenantHostRegistry = hostRegistries.getTenantHostRegistry();
log.log(LogLevel.DEBUG, "hosts in tenant host registry '" + tenantHostRegistry + "' " + tenantHostRegistry.getAllHosts());
TenantName tenant = tenantHostRegistry.getKeyForHost(hostname);
if (tenant == null)
return createError(hostname);
log.log(LogLevel.DEBUG, "tenant=" + tenant);
HostRegistry<ApplicationId> applicationIdHostRegistry = hostRegistries.getApplicationHostRegistry(tenant);
ApplicationId applicationId;
if (applicationIdHostRegistry == null)
return createError(hostname);
applicationId = applicationIdHostRegistry.getKeyForHost(hostname);
log.log(LogLevel.DEBUG, "applicationId=" + applicationId);
if (applicationId == null) {
return createError(hostname);
} else {
log.log(LogLevel.DEBUG, "hosts in application host registry '" + applicationIdHostRegistry + "' " + applicationIdHostRegistry.getAllHosts());
return new HostResponse(Response.Status.OK, applicationId, zone);
}
}
use of com.yahoo.config.provision.TenantName in project vespa by vespa-engine.
the class GetConfigProcessor method run.
// TODO: Increment statistics (Metrics) failed counters when requests fail
public void run() {
// Request has already been detached
if (!request.validateParameters()) {
// Error code is set in verifyParameters if parameters are not OK.
log.log(LogLevel.WARNING, "Parameters for request " + request + " did not validate: " + request.errorCode() + " : " + request.errorMessage());
respond(request);
return;
}
Trace trace = request.getRequestTrace();
if (logDebug(trace)) {
debugLog(trace, "GetConfigProcessor.run() on " + localHostName);
}
Optional<TenantName> tenant = rpcServer.resolveTenant(request, trace);
// fabricate an empty request to cause the sentinel to stop all running services
if (rpcServer.isHostedVespa() && rpcServer.allTenantsLoaded() && !tenant.isPresent() && isSentinelConfigRequest(request)) {
returnEmpty(request);
return;
}
GetConfigContext context = rpcServer.createGetConfigContext(tenant, request, trace);
if (context == null || !context.requestHandler().hasApplication(context.applicationId(), Optional.<Version>empty())) {
handleError(request, ErrorCode.APPLICATION_NOT_LOADED, "No application exists");
return;
}
Optional<Version> vespaVersion = rpcServer.useRequestVersion() ? request.getVespaVersion().map(VespaVersion::toString).map(Version::fromString) : Optional.empty();
if (logDebug(trace)) {
debugLog(trace, "Using version " + getPrintableVespaVersion(vespaVersion));
}
if (!context.requestHandler().hasApplication(context.applicationId(), vespaVersion)) {
handleError(request, ErrorCode.UNKNOWN_VESPA_VERSION, "Unknown Vespa version in request: " + getPrintableVespaVersion(vespaVersion));
return;
}
this.logPre = Tenants.logPre(context.applicationId());
ConfigResponse config;
try {
config = rpcServer.resolveConfig(request, context, vespaVersion);
} catch (UnknownConfigDefinitionException e) {
handleError(request, ErrorCode.UNKNOWN_DEFINITION, "Unknown config definition " + request.getConfigKey());
return;
} catch (UnknownConfigIdException e) {
handleError(request, ErrorCode.ILLEGAL_CONFIGID, "Illegal config id " + request.getConfigKey().getConfigId());
return;
} catch (Throwable e) {
log.log(Level.SEVERE, "Unexpected error handling config request", e);
handleError(request, ErrorCode.INTERNAL_ERROR, "Internal error " + e.getMessage());
return;
}
// config == null is not an error, but indicates that the config will be returned later.
if ((config != null) && (!config.hasEqualConfig(request) || config.hasNewerGeneration(request) || forceResponse)) {
// debugLog(trace, "config response before encoding:" + config.toString());
request.addOkResponse(request.payloadFromResponse(config), config.getGeneration(), config.getConfigMd5());
if (logDebug(trace)) {
debugLog(trace, "return response: " + request.getShortDescription());
}
respond(request);
} else {
if (logDebug(trace)) {
debugLog(trace, "delaying response " + request.getShortDescription());
}
rpcServer.delayResponse(request, context);
}
}
use of com.yahoo.config.provision.TenantName in project vespa by vespa-engine.
the class RpcServer method createGetConfigContext.
/**
* Returns the context for this request, or null if the server is not properly set up with handlers
*/
public GetConfigContext createGetConfigContext(Optional<TenantName> optionalTenant, JRTServerConfigRequest request, Trace trace) {
if ("*".equals(request.getConfigKey().getConfigId())) {
return GetConfigContext.create(ApplicationId.global(), superModelRequestHandler, trace);
}
// perhaps needed for non-hosted?
TenantName tenant = optionalTenant.orElse(TenantName.defaultName());
if (!hasRequestHandler(tenant)) {
String msg = Tenants.logPre(tenant) + "Unable to find request handler for tenant. Requested from host '" + request.getClientHostName() + "'";
metrics.incUnknownHostRequests();
trace.trace(TRACELEVEL, msg);
log.log(LogLevel.WARNING, msg);
return null;
}
RequestHandler handler = getRequestHandler(tenant);
ApplicationId applicationId = handler.resolveApplicationId(request.getClientHostName());
if (trace.shouldTrace(TRACELEVEL_DEBUG)) {
trace.trace(TRACELEVEL_DEBUG, "Host '" + request.getClientHostName() + "' should have config from application '" + applicationId + "'");
}
return GetConfigContext.create(applicationId, handler, trace);
}
use of com.yahoo.config.provision.TenantName in project vespa by vespa-engine.
the class SuperModelControllerTest method test_lb_config_multiple_apps.
@Test
public void test_lb_config_multiple_apps() throws IOException, SAXException {
Map<TenantName, Map<ApplicationId, ApplicationInfo>> models = new LinkedHashMap<>();
models.put(TenantName.from("t1"), new LinkedHashMap<>());
models.put(TenantName.from("t2"), new LinkedHashMap<>());
File testApp1 = new File("src/test/resources/deploy/app");
File testApp2 = new File("src/test/resources/deploy/advancedapp");
File testApp3 = new File("src/test/resources/deploy/advancedapp");
// TODO must fix equals, hashCode on Tenant
Version vespaVersion = Version.fromIntValues(1, 2, 3);
models.get(TenantName.from("t1")).put(applicationId("mysimpleapp"), new ApplicationInfo(applicationId("mysimpleapp"), 4l, new VespaModel(FilesApplicationPackage.fromFile(testApp1))));
models.get(TenantName.from("t1")).put(applicationId("myadvancedapp"), new ApplicationInfo(applicationId("myadvancedapp"), 4l, new VespaModel(FilesApplicationPackage.fromFile(testApp2))));
models.get(TenantName.from("t2")).put(applicationId("minetooadvancedapp"), new ApplicationInfo(applicationId("minetooadvancedapp"), 4l, new VespaModel(FilesApplicationPackage.fromFile(testApp3))));
SuperModel superModel = new SuperModel(models);
SuperModelController han = new SuperModelController(new SuperModelConfigProvider(superModel, Zone.defaultZone()), new TestConfigDefinitionRepo(), 2, new UncompressedConfigResponseFactory());
LbServicesConfig.Builder lb = new LbServicesConfig.Builder();
han.getSuperModel().getConfig(lb);
LbServicesConfig lbc = new LbServicesConfig(lb);
assertThat(lbc.tenants().size(), is(2));
assertThat(lbc.tenants("t1").applications().size(), is(2));
assertThat(lbc.tenants("t2").applications().size(), is(1));
assertThat(lbc.tenants("t2").applications("minetooadvancedapp:prod:default:default").hosts().size(), is(1));
assertQrServer(lbc.tenants("t2").applications("minetooadvancedapp:prod:default:default"));
}
Aggregations