use of com.yahoo.container.jdisc.HttpRequest in project vespa by vespa-engine.
the class FeedHandlerCompressionTest method testUnzipStreamIfNeeded.
@Test
public void testUnzipStreamIfNeeded() throws Exception {
final String testData = "foo bar";
InputStream inputStream = new ByteArrayInputStream(compress(testData));
HttpRequest httpRequest = mock(HttpRequest.class);
when(httpRequest.getHeader("content-encoding")).thenReturn("gzip");
InputStream decompressedStream = FeedHandler.unzipStreamIfNeeded(inputStream, httpRequest);
final StringBuilder processedInput = new StringBuilder();
while (true) {
int readValue = decompressedStream.read();
if (readValue < 0) {
break;
}
processedInput.append((char) readValue);
}
assertThat(processedInput.toString(), is(testData));
}
use of com.yahoo.container.jdisc.HttpRequest in project vespa by vespa-engine.
the class ApplicationApiHandler method toSlime.
private void toSlime(Cursor object, Application application, HttpRequest request) {
object.setString("application", application.id().application().value());
object.setString("instance", application.id().instance().value());
// Currently deploying change
if (application.change().isPresent()) {
Cursor deployingObject = object.setObject("deploying");
application.change().platform().ifPresent(v -> deployingObject.setString("version", v.toString()));
application.change().application().filter(v -> v != ApplicationVersion.unknown).ifPresent(v -> toSlime(v, deployingObject.setObject("revision")));
}
// Jobs sorted according to deployment spec
List<JobStatus> jobStatus = controller.applications().deploymentTrigger().deploymentOrder().sortBy(application.deploymentSpec(), application.deploymentJobs().jobStatus().values());
Cursor deploymentsArray = object.setArray("deploymentJobs");
for (JobStatus job : jobStatus) {
Cursor jobObject = deploymentsArray.addObject();
jobObject.setString("type", job.type().jobName());
jobObject.setBool("success", job.isSuccess());
job.lastTriggered().ifPresent(jobRun -> toSlime(jobRun, jobObject.setObject("lastTriggered")));
job.lastCompleted().ifPresent(jobRun -> toSlime(jobRun, jobObject.setObject("lastCompleted")));
job.firstFailing().ifPresent(jobRun -> toSlime(jobRun, jobObject.setObject("firstFailing")));
job.lastSuccess().ifPresent(jobRun -> toSlime(jobRun, jobObject.setObject("lastSuccess")));
}
// Change blockers
Cursor changeBlockers = object.setArray("changeBlockers");
application.deploymentSpec().changeBlocker().forEach(changeBlocker -> {
Cursor changeBlockerObject = changeBlockers.addObject();
changeBlockerObject.setBool("versions", changeBlocker.blocksVersions());
changeBlockerObject.setBool("revisions", changeBlocker.blocksRevisions());
changeBlockerObject.setString("timeZone", changeBlocker.window().zone().getId());
Cursor days = changeBlockerObject.setArray("days");
changeBlocker.window().days().stream().map(DayOfWeek::getValue).forEach(days::addLong);
Cursor hours = changeBlockerObject.setArray("hours");
changeBlocker.window().hours().forEach(hours::addLong);
});
// Compile version. The version that should be used when building an application
object.setString("compileVersion", application.oldestDeployedVersion().orElse(controller.systemVersion()).toFullString());
// Rotation
Cursor globalRotationsArray = object.setArray("globalRotations");
application.rotation().ifPresent(rotation -> {
globalRotationsArray.addString(rotation.url().toString());
globalRotationsArray.addString(rotation.secureUrl().toString());
object.setString("rotationId", rotation.id().asString());
});
// Deployments sorted according to deployment spec
List<Deployment> deployments = controller.applications().deploymentTrigger().deploymentOrder().sortBy(application.deploymentSpec().zones(), application.deployments().values());
Cursor instancesArray = object.setArray("instances");
for (Deployment deployment : deployments) {
Cursor deploymentObject = instancesArray.addObject();
deploymentObject.setString("environment", deployment.zone().environment().value());
deploymentObject.setString("region", deployment.zone().region().value());
// pointless
deploymentObject.setString("instance", application.id().instance().value());
if (application.rotation().isPresent()) {
Map<String, RotationStatus> rotationHealthStatus = application.rotation().map(rotation -> controller.getHealthStatus(rotation.dnsName())).orElse(Collections.emptyMap());
setRotationStatus(deployment, rotationHealthStatus, deploymentObject);
}
if (// List full deployment information when recursive.
recurseOverDeployments(request))
toSlime(deploymentObject, new DeploymentId(application.id(), deployment.zone()), deployment, request);
else
deploymentObject.setString("url", withPath(request.getUri().getPath() + "/environment/" + deployment.zone().environment().value() + "/region/" + deployment.zone().region().value() + "/instance/" + application.id().instance().value(), request.getUri()).toString());
}
// Metrics
Cursor metricsObject = object.setObject("metrics");
metricsObject.setDouble("queryServiceQuality", application.metrics().queryServiceQuality());
metricsObject.setDouble("writeServiceQuality", application.metrics().writeServiceQuality());
application.ownershipIssueId().ifPresent(issueId -> object.setString("ownershipIssueId", issueId.value()));
application.deploymentJobs().issueId().ifPresent(issueId -> object.setString("deploymentIssueId", issueId.value()));
}
use of com.yahoo.container.jdisc.HttpRequest in project vespa by vespa-engine.
the class ApplicationApiHandler method toSlime.
private void toSlime(Cursor response, DeploymentId deploymentId, Deployment deployment, HttpRequest request) {
Cursor serviceUrlArray = response.setArray("serviceUrls");
controller.applications().getDeploymentEndpoints(deploymentId).ifPresent(endpoints -> endpoints.forEach(endpoint -> serviceUrlArray.addString(endpoint.toString())));
response.setString("nodes", withPath("/zone/v2/" + deploymentId.zoneId().environment() + "/" + deploymentId.zoneId().region() + "/nodes/v2/node/?&recursive=true&application=" + deploymentId.applicationId().tenant() + "." + deploymentId.applicationId().application() + "." + deploymentId.applicationId().instance(), request.getUri()).toString());
controller.zoneRegistry().getLogServerUri(deploymentId).ifPresent(elkUrl -> response.setString("elkUrl", elkUrl.toString()));
response.setString("yamasUrl", monitoringSystemUri(deploymentId).toString());
response.setString("version", deployment.version().toFullString());
response.setString("revision", deployment.applicationVersion().id());
response.setLong("deployTimeEpochMs", deployment.at().toEpochMilli());
controller.zoneRegistry().getDeploymentTimeToLive(deploymentId.zoneId()).ifPresent(deploymentTimeToLive -> response.setLong("expiryTimeEpochMs", deployment.at().plus(deploymentTimeToLive).toEpochMilli()));
controller.applications().get(deploymentId.applicationId()).flatMap(application -> application.deploymentJobs().projectId()).ifPresent(i -> response.setString("screwdriverId", String.valueOf(i)));
sourceRevisionToSlime(deployment.applicationVersion().source(), response);
// Cost
DeploymentCost appCost = deployment.calculateCost();
Cursor costObject = response.setObject("cost");
toSlime(appCost, costObject);
// Metrics
DeploymentMetrics metrics = deployment.metrics();
Cursor metricsObject = response.setObject("metrics");
metricsObject.setDouble("queriesPerSecond", metrics.queriesPerSecond());
metricsObject.setDouble("writesPerSecond", metrics.writesPerSecond());
metricsObject.setDouble("documentCount", metrics.documentCount());
metricsObject.setDouble("queryLatencyMillis", metrics.queryLatencyMillis());
metricsObject.setDouble("writeLatencyMillis", metrics.writeLatencyMillis());
}
use of com.yahoo.container.jdisc.HttpRequest in project vespa by vespa-engine.
the class QueryProfileIntegrationTestCase method testUntyped.
public void testUntyped() {
String configId = "dir:src/test/java/com/yahoo/search/query/profile/config/test/untyped";
System.setProperty("config.id", configId);
Container container = new Container();
HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper(container, configId);
SearchHandler searchHandler = (SearchHandler) configurer.getRequestHandlerRegistry().getComponent(SearchHandler.class.getName());
// Should get "default" query profile containing the "test" search chain containing the "test" searcher
HttpRequest request = HttpRequest.createTestRequest("search", Method.GET);
// Cast to access content directly
HttpSearchResponse response = (HttpSearchResponse) searchHandler.handle(request);
assertNotNull(response.getResult().hits().get("from:test"));
// Should get the "test' query profile containing the "default" search chain containing the "default" searcher
request = HttpRequest.createTestRequest("search?queryProfile=test", Method.GET);
// Cast to access content directly
response = (HttpSearchResponse) searchHandler.handle(request);
assertNotNull(response.getResult().hits().get("from:default"));
// Should get "default" query profile, but override the search chain to default
request = HttpRequest.createTestRequest("search?searchChain=default", Method.GET);
// Cast to access content directly
response = (HttpSearchResponse) searchHandler.handle(request);
assertNotNull(response.getResult().hits().get("from:default"));
// Tests a profile setting hits and offset
request = HttpRequest.createTestRequest("search?queryProfile=hitsoffset", Method.GET);
// Cast to access content directly
response = (HttpSearchResponse) searchHandler.handle(request);
assertEquals(20, response.getQuery().getHits());
assertEquals(80, response.getQuery().getOffset());
// Tests a non-resolved profile request
request = HttpRequest.createTestRequest("search?queryProfile=none", Method.GET);
// Cast to access content directly
response = (HttpSearchResponse) searchHandler.handle(request);
assertNotNull("Got an error", response.getResult().hits().getError());
assertEquals("Could not resolve query profile 'none'", response.getResult().hits().getError().getDetailedMessage());
// Tests that properties in objects owned by query is handled correctly
request = HttpRequest.createTestRequest("search?query=word&queryProfile=test", Method.GET);
// Cast to access content directly
response = (HttpSearchResponse) searchHandler.handle(request);
assertEquals("index", response.getQuery().getModel().getDefaultIndex());
assertEquals("index:word", response.getQuery().getModel().getQueryTree().toString());
configurer.shutdown();
}
use of com.yahoo.container.jdisc.HttpRequest in project vespa by vespa-engine.
the class XmlReadingTestCase method testValid.
@Test
public void testValid() {
QueryProfileRegistry registry = new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/validxml");
CompiledQueryProfileRegistry cRegistry = registry.compile();
QueryProfileType rootType = registry.getType("rootType");
assertEquals(1, rootType.inherited().size());
assertEquals("native", rootType.inherited().get(0).getId().getName());
assertTrue(rootType.isStrict());
assertTrue(rootType.getMatchAsPath());
FieldDescription timeField = rootType.getField("time");
assertTrue(timeField.isMandatory());
assertEquals("long", timeField.getType().toInstanceDescription());
FieldDescription userField = rootType.getField("user");
assertFalse(userField.isMandatory());
assertEquals("reference to a query profile of type 'user'", userField.getType().toInstanceDescription());
QueryProfileType user = registry.getType("user");
assertEquals(0, user.inherited().size());
assertFalse(user.isStrict());
assertFalse(user.getMatchAsPath());
assertTrue(userField.isOverridable());
FieldDescription ageField = user.getField("age");
assertTrue(ageField.isMandatory());
assertEquals("integer", ageField.getType().toInstanceDescription());
FieldDescription robotField = user.getField("robot");
assertFalse(robotField.isMandatory());
assertFalse(robotField.isOverridable());
assertEquals("boolean", robotField.getType().toInstanceDescription());
CompiledQueryProfile defaultProfile = cRegistry.getComponent("default");
assertNull(defaultProfile.getType());
assertEquals("20", defaultProfile.get("hits"));
assertFalse(defaultProfile.isOverridable(new CompoundName("hits"), null));
assertFalse(defaultProfile.isOverridable(new CompoundName("user.trusted"), null));
assertEquals("false", defaultProfile.get("user.trusted"));
CompiledQueryProfile referencingProfile = cRegistry.getComponent("referencingModelSettings");
assertNull(referencingProfile.getType());
assertEquals("some query", referencingProfile.get("model.queryString"));
assertEquals("aDefaultIndex", referencingProfile.get("model.defaultIndex"));
// Request parameters here should be ignored
HttpRequest request = HttpRequest.createTestRequest("?query=foo&user.trusted=true&default-index=title", Method.GET);
Query query = new Query(request, defaultProfile);
assertEquals("false", query.properties().get("user.trusted"));
assertEquals("default", query.getModel().getDefaultIndex());
assertEquals("default", query.properties().get("default-index"));
CompiledQueryProfile rootProfile = cRegistry.getComponent("root");
assertEquals("rootType", rootProfile.getType().getId().getName());
assertEquals(30, rootProfile.get("hits"));
assertEquals(3, rootProfile.get("traceLevel"));
assertTrue(rootProfile.isOverridable(new CompoundName("hits"), null));
QueryProfile someUser = registry.getComponent("someUser");
assertEquals("5", someUser.get("sub.test"));
assertEquals(18, someUser.get("age"));
// aliases
assertEquals(18, someUser.get("alder"));
assertEquals(18, someUser.get("anno"));
assertEquals(18, someUser.get("aLdER"));
assertEquals(18, someUser.get("ANNO"));
// Only aliases are case insensitive
assertNull(someUser.get("Age"));
Map<String, String> context = new HashMap<>();
context.put("x", "x1");
assertEquals(37, someUser.get("alder", context, null));
assertEquals(37, someUser.get("anno", context, null));
assertEquals(37, someUser.get("aLdER", context, null));
assertEquals(37, someUser.get("ANNO", context, null));
assertEquals("male", someUser.get("gender", context, null));
assertEquals("male", someUser.get("sex", context, null));
assertEquals("male", someUser.get("Sex", context, null));
// Only aliases are case insensitive
assertNull(someUser.get("Gender", context, null));
}
Aggregations