Search in sources :

Example 1 with HttpResult

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;
}
Also used : HttpRequest(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest) AsyncOperationImpl(com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperationImpl) HttpResult(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult) SyncHttpClient(com.yahoo.vespa.clustercontroller.utils.communication.http.SyncHttpClient)

Example 2 with HttpResult

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()));
            }
        };
    }
}
Also used : HttpRequest(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest) HttpResult(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult)

Example 3 with HttpResult

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;
}
Also used : HttpRequest(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest) StatusPageServer(com.yahoo.vespa.clustercontroller.core.status.statuspage.StatusPageServer) HttpResult(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult) StatusPageResponse(com.yahoo.vespa.clustercontroller.core.status.statuspage.StatusPageResponse)

Example 4 with HttpResult

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;
}
Also used : StringWriter(java.io.StringWriter) HttpResult(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult)

Example 5 with HttpResult

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();
}
Also used : HttpRequest(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest) StatusHandler(com.yahoo.vespa.clustercontroller.core.status.StatusHandler) Distribution(com.yahoo.vdslib.distribution.Distribution) HttpResult(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

HttpResult (com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult)16 HttpRequest (com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest)13 Test (org.junit.Test)7 JSONObject (org.codehaus.jettison.json.JSONObject)3 StringWriter (java.io.StringWriter)2 Distribution (com.yahoo.vdslib.distribution.Distribution)1 StatusHandler (com.yahoo.vespa.clustercontroller.core.status.StatusHandler)1 StatusPageResponse (com.yahoo.vespa.clustercontroller.core.status.statuspage.StatusPageResponse)1 StatusPageServer (com.yahoo.vespa.clustercontroller.core.status.statuspage.StatusPageServer)1 AsyncOperationImpl (com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperationImpl)1 SyncHttpClient (com.yahoo.vespa.clustercontroller.utils.communication.http.SyncHttpClient)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Header (org.apache.http.Header)1 HttpEntity (org.apache.http.HttpEntity)1 HttpHost (org.apache.http.HttpHost)1 HttpResponse (org.apache.http.HttpResponse)1 HttpDelete (org.apache.http.client.methods.HttpDelete)1