use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult 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.HttpResult 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.HttpResult in project vespa by vespa-engine.
the class StatusHandler method handleClusterRequest.
private HttpResult handleClusterRequest(String clusterName, String fleetControllerPath) throws InterruptedException {
ContainerStatusPageServer statusServer = statusClusters.get(clusterName);
if (statusServer == null) {
return new HttpResult().setHttpCode(404, "No controller exists for cluster '" + clusterName + "'.");
}
if (fleetControllerPath == null || fleetControllerPath.isEmpty()) {
fleetControllerPath = "/";
}
StatusPageServer.HttpRequest req = new StatusPageServer.HttpRequest(fleetControllerPath);
req.setPathPrefix("/clustercontroller-status/v1");
StatusPageResponse response = statusServer.getStatus(req);
HttpResult result = new HttpResult();
if (response.getResponseCode() != null) {
result.setHttpCode(response.getResponseCode().getCode(), response.getResponseCode().getMessage());
}
if (response.getContentType() != null) {
result.addHeader("Content-Type", response.getContentType());
}
result.setContent(new String(response.getOutputStream().toByteArray()));
return result;
}
use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult in project vespa by vespa-engine.
the class StatusHandler method handleClusterListRequest.
public HttpResult handleClusterListRequest() {
HttpResult result = new HttpResult();
result.addHeader("Content-Type", "text/html");
StringWriter sw = new StringWriter();
sw.append("<title>clusters</title>\n");
for (String s : statusClusters.getAll().keySet()) {
sw.append("<a href=\"./").append(s).append("\">").append(s).append("</a><br>").append("\n");
}
result.setContent(sw.toString());
return result;
}
use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult 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();
}
Aggregations