use of com.yahoo.vespa.config.server.GetConfigContext in project vespa by vespa-engine.
the class DelayedConfigResponseTest method testDelayedConfigResponses.
@Test
public void testDelayedConfigResponses() {
MockRpc rpc = new MockRpc(13337);
DelayedConfigResponses responses = new DelayedConfigResponses(rpc, 1, false);
assertThat(responses.size(), is(0));
JRTServerConfigRequest req = createRequest("foo", "md5", "myid", "mymd5", 3, 1000000, "bar");
req.setDelayedResponse(true);
GetConfigContext context = GetConfigContext.testContext(ApplicationId.defaultId());
responses.delayResponse(req, context);
assertThat(responses.size(), is(0));
req.setDelayedResponse(false);
responses.delayResponse(req, context);
responses.delayResponse(createRequest("foolio", "md5", "myid", "mymd5", 3, 100000, "bar"), context);
assertThat(responses.size(), is(2));
assertTrue(req.isDelayedResponse());
List<DelayedConfigResponses.DelayedConfigResponse> it = responses.allDelayedResponses();
assertTrue(!it.isEmpty());
}
use of com.yahoo.vespa.config.server.GetConfigContext in project vespa by vespa-engine.
the class DelayedConfigResponseTest method testDelayResponseRemove.
@Test
public void testDelayResponseRemove() {
GetConfigContext context = GetConfigContext.testContext(ApplicationId.defaultId());
MockRpc rpc = new MockRpc(13337);
DelayedConfigResponses responses = new DelayedConfigResponses(rpc, 1, false);
responses.delayResponse(createRequest("foolio", "md5", "myid", "mymd5", 3, 100000, "bar"), context);
assertThat(responses.size(), is(1));
responses.allDelayedResponses().get(0).cancelAndRemove();
assertThat(responses.size(), is(0));
}
use of com.yahoo.vespa.config.server.GetConfigContext 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);
}
}
Aggregations