Search in sources :

Example 1 with HttpRequest

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;
}
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 HttpRequest

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

Example 3 with HttpRequest

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

Example 4 with HttpRequest

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();
}
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)

Example 5 with HttpRequest

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

Aggregations

HttpRequest (com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest)13 HttpResult (com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult)12 Test (org.junit.Test)8 JSONObject (org.codehaus.jettison.json.JSONObject)2 Distribution (com.yahoo.vdslib.distribution.Distribution)1 StatusHandler (com.yahoo.vespa.clustercontroller.core.status.StatusHandler)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 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)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 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpPost (org.apache.http.client.methods.HttpPost)1 HttpPut (org.apache.http.client.methods.HttpPut)1