use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest in project vespa by vespa-engine.
the class ApacheAsyncHttpClient method execute.
@Override
public AsyncOperation<HttpResult> execute(HttpRequest r) {
// Gonna modify it to extract proxy information
final HttpRequest request = r.clone();
final Settings settings = new Settings(request);
final SyncHttpClient instance = getFittingInstance(settings);
final AsyncOperationImpl<HttpResult> op = new AsyncOperationImpl<>(r.toString(), r.toString(true));
executor.execute(new Runnable() {
@Override
public void run() {
HttpResult result;
Exception failure = null;
try {
result = instance.execute(request);
} catch (Exception e) {
result = new HttpResult().setHttpCode(500, "Apache client failed to execute request.");
failure = e;
}
insertInstance(settings, instance);
// call can reuse same instance
if (failure != null) {
op.setFailure(failure, result);
} else {
op.setResult(result);
}
}
});
return op;
}
use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest in project vespa by vespa-engine.
the class JDiscHttpRequestHandler method handle.
@Override
public com.yahoo.container.jdisc.HttpResponse handle(com.yahoo.container.jdisc.HttpRequest request) {
final HttpRequest legacyRequest = new HttpRequest();
final com.yahoo.jdisc.http.HttpRequest jDiscRequest = request.getJDiscRequest();
legacyRequest.setHost(request.getUri().getHost());
setOperation(legacyRequest, request.getMethod());
legacyRequest.setPort(request.getUri().getPort());
legacyRequest.setPath(request.getUri().getPath());
copyPostData(request, legacyRequest);
copyRequestHeaders(legacyRequest, jDiscRequest);
copyParameters(legacyRequest, jDiscRequest);
legacyRequest.setTimeout(Duration.ofMinutes(60).toMillis());
try {
final HttpResult result = requestHandler.handleRequest(legacyRequest);
log.fine("Got result " + result.toString(true));
return copyResponse(result);
} catch (Exception e) {
log.warning("Caught exception while handling request: " + e.getMessage());
return new com.yahoo.container.jdisc.HttpResponse(500) {
@Override
public void render(OutputStream outputStream) throws IOException {
outputStream.write(Utf8.toBytes(e.getMessage()));
}
};
}
}
use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest in project vespa by vespa-engine.
the class JDiscHttpRequestHandlerTest method testInvalidMethod.
@Test
public void testInvalidMethod() throws Exception {
try {
HttpRequest request = new HttpRequest();
JDiscHttpRequestHandler.setOperation(request, com.yahoo.jdisc.http.HttpRequest.Method.CONNECT);
fail("Control should not reach here");
} catch (IllegalStateException e) {
assertEquals("Unhandled method CONNECT", e.getMessage());
}
}
use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest in project vespa by vespa-engine.
the class StatusPagesTest method testStatusThroughContainer.
@Test
public void testStatusThroughContainer() throws Exception {
startingTest("StatusPagesTest::testStatusThroughContainer()");
FleetControllerOptions options = new FleetControllerOptions("mycluster");
options.setStorageDistribution(new Distribution(Distribution.getDefaultDistributionConfig(3, 10)));
final StatusHandler.ContainerStatusPageServer statusServer = new StatusHandler.ContainerStatusPageServer();
setUpFleetController(true, options, true, statusServer);
setUpVdsNodes(true, new DummyVdsNodeOptions());
waitForStableSystem();
// ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 100, 100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1000));
// FleetControllerComponent fcComp = new FleetControllerComponent();
// fcComp.addFleetController("mycluster", fleetController, statusServer);
StatusHandler comp = new StatusHandler(new StatusHandler.ClusterStatusPageServerSet() {
@Override
public StatusHandler.ContainerStatusPageServer get(String cluster) {
return ("mycluster".equals(cluster) ? statusServer : null);
}
@Override
public Map<String, StatusHandler.ContainerStatusPageServer> getAll() {
Map<String, StatusHandler.ContainerStatusPageServer> map = new HashMap<>();
map.put("mycluster", statusServer);
return map;
}
});
{
HttpRequest request = new HttpRequest().setPath("/clustercontroller-status/v1");
HttpResult result = comp.handleRequest(request);
assertEquals(result.toString(true), 200, result.getHttpReturnCode());
assertEquals("<title>clusters</title>\n<a href=\"./mycluster\">mycluster</a><br>\n", result.getContent().toString());
}
{
HttpRequest request = new HttpRequest().setPath("/clustercontroller-status/v1/");
HttpResult result = comp.handleRequest(request);
assertEquals(result.toString(true), 200, result.getHttpReturnCode());
assertEquals("<title>clusters</title>\n<a href=\"./mycluster\">mycluster</a><br>\n", result.getContent().toString());
}
{
HttpRequest request = new HttpRequest().setPath("/clustercontroller-status/v1/mycluster");
HttpResult result = comp.handleRequest(request);
assertEquals(result.toString(true), 200, result.getHttpReturnCode());
assertTrue(result.toString(true), result.getContent().toString().contains("mycluster Cluster Controller 0 Status Page"));
}
{
HttpRequest request = new HttpRequest().setPath("/clustercontroller-status/v1/mycluster/");
HttpResult result = comp.handleRequest(request);
assertEquals(result.toString(true), 200, result.getHttpReturnCode());
assertTrue(result.toString(true), result.getContent().toString().contains("mycluster Cluster Controller 0 Status Page"));
assertTrue(result.toString(true), result.getContent().toString().contains("href=\"mycluster/node=distributor.0\""));
assertTrue(result.toString(true), result.getContent().toString().contains("href=\"mycluster/node=storage.0\""));
}
{
HttpRequest request = new HttpRequest().setPath("/clustercontroller-status/v1/mycluster/node=storage.0");
HttpResult result = comp.handleRequest(request);
assertEquals(result.toString(true), 200, result.getHttpReturnCode());
assertTrue(result.toString(true), result.getContent().toString().contains("Node status for storage.0"));
assertTrue(result.toString(true), result.getContent().toString().contains("href=\"..\""));
}
{
HttpRequest request = new HttpRequest().setPath("/clustercontroller-status/v1/foo");
HttpResult result = comp.handleRequest(request);
assertEquals(result.toString(true), 404, result.getHttpReturnCode());
}
{
HttpRequest request = new HttpRequest().setPath("/foobar/v1/mycluster/");
HttpResult result = comp.handleRequest(request);
assertEquals(result.toString(true), 404, result.getHttpReturnCode());
}
{
HttpRequest request = new HttpRequest().setPath("/clustercontroller-status/v2/");
HttpResult result = comp.handleRequest(request);
assertEquals(result.toString(true), 404, result.getHttpReturnCode());
}
// executor.shutdown();
}
use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest in project vespa by vespa-engine.
the class StateRestAPITest method deadline_exceeded_exception_returns_http_504_error.
@Test
public void deadline_exceeded_exception_returns_http_504_error() throws Exception {
setupDummyStateApi();
stateApi.induceException(new DeadlineExceededException("argh!"));
HttpResult result = execute(new HttpRequest().setPath("/cluster/v2"));
assertEquals(result.toString(true), 504, result.getHttpReturnCode());
assertEquals(result.toString(true), "Gateway Timeout", result.getHttpReturnCodeDescription());
assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type"));
String expected = "{\"message\":\"argh!\"}";
assertEquals(expected, result.getContent().toString());
}
Aggregations