Search in sources :

Example 66 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project cdap by caskdata.

the class RouterPathTest method testRouterExplorePathLookUp.

@Test
public void testRouterExplorePathLookUp() throws Exception {
    String explorePath = "/v3/namespaces/default//data///explore//datasets////mydataset//enable";
    HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("POST"), explorePath);
    RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, explorePath, httpRequest);
    Assert.assertEquals(RouterPathLookup.EXPLORE_HTTP_USER_SERVICE, result);
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test)

Example 67 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project cdap by caskdata.

the class RouterPathTest method testLogPath.

@Test
public void testLogPath() throws Exception {
    // Following URIs might not give actual results but we want to test resilience of Router Path Lookup
    String flowPath = "/v3/namespaces/default/apps//InvalidApp///flows/FlowName/logs/";
    HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), flowPath);
    RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, flowPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.METRICS, result);
    flowPath = "///v3/namespaces/default///apps/InvalidApp/flows/FlowName/////logs";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("POST"), flowPath);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, flowPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.METRICS, result);
    flowPath = "/v3/namespaces/default/apps/InvalidApp/service/ServiceName/runs/7e6adc79-0f5d-4252-70817ea47698/logs/";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), flowPath);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, flowPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.METRICS, result);
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test)

Example 68 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project cdap by caskdata.

the class RouterPathTest method testServicePath.

@Test
public void testServicePath() throws Exception {
    // The following two should resort to resort to APP_FABRIC_HTTP, because there is no actual method being called.
    String servicePath = "v3/namespaces/default/apps/AppName/services/CatalogLookup//methods////";
    HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("PUT"), servicePath);
    httpRequest.headers().set(Constants.Gateway.API_KEY, API_KEY);
    RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, servicePath, httpRequest);
    Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
    servicePath = "v3/namespaces/some/apps/otherAppName/services/CatalogLookup//methods////";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), servicePath);
    httpRequest.headers().set(Constants.Gateway.API_KEY, API_KEY);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, servicePath, httpRequest);
    Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
    // v3 servicePaths
    servicePath = "/v3/namespaces/testnamespace/apps//PurchaseHistory///services/CatalogLookup///methods//ping/1";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), servicePath);
    httpRequest.headers().set(Constants.Gateway.API_KEY, API_KEY);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, servicePath, httpRequest);
    Assert.assertEquals("service.testnamespace.PurchaseHistory.CatalogLookup", result.getServiceName());
    Assert.assertNull(result.getVersion());
    servicePath = "///v3/namespaces/testnamespace//apps/PurchaseHistory-123//services/weird!service@@NAme///methods/" + "echo/someParam";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("POST"), servicePath);
    httpRequest.headers().set(Constants.Gateway.API_KEY, API_KEY);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, servicePath, httpRequest);
    Assert.assertEquals("service.testnamespace.PurchaseHistory-123.weird!service@@NAme", result.getServiceName());
    Assert.assertNull(result.getVersion());
    servicePath = "v3/namespaces/testnamespace/apps/SomeApp_Name/services/CatalogLookup/methods/getHistory/itemID";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), servicePath);
    httpRequest.headers().set(Constants.Gateway.API_KEY, API_KEY);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, servicePath, httpRequest);
    Assert.assertEquals("service.testnamespace.SomeApp_Name.CatalogLookup", result.getServiceName());
    Assert.assertNull(result.getVersion());
    servicePath = "v3/namespaces/testnamespace/apps/AppName/services/CatalogLookup//methods////";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("PUT"), servicePath);
    httpRequest.headers().set(Constants.Gateway.API_KEY, API_KEY);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, servicePath, httpRequest);
    Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
    servicePath = "v3/namespaces/testnamespace/apps/AppName/services/CatalogLookup////methods////";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), servicePath);
    httpRequest.headers().set(Constants.Gateway.API_KEY, API_KEY);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, servicePath, httpRequest);
    Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test)

Example 69 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project cdap by caskdata.

the class DefaultStreamManager method getEvents.

private List<StreamEvent> getEvents(Id.Stream streamId, String startTime, String endTime, int limit) throws IOException {
    long start = TimeMathParser.parseTime(startTime, TimeUnit.MILLISECONDS);
    long end = TimeMathParser.parseTime(endTime, TimeUnit.MILLISECONDS);
    String path = String.format("/v3/namespaces/%s/streams/%s/events?start=%d&end=%d&limit=%d", streamId.getNamespaceId(), streamId.getId(), start, end, limit);
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, path);
    MockResponder responder = new MockResponder();
    try {
        streamFetchHandler.fetch(httpRequest, responder, streamId.getNamespaceId(), streamId.getId(), startTime, endTime, limit);
    } catch (Exception e) {
        Throwables.propagateIfPossible(e, IOException.class);
        throw Throwables.propagate(e);
    }
    if (responder.getStatus() != HttpResponseStatus.OK) {
        throw new IOException("Failed to read from stream. Status = " + responder.getStatus());
    }
    return responder.decodeResponseContent(STREAM_EVENT_LIST_TYPE, GSON);
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) MockResponder(co.cask.cdap.internal.MockResponder) IOException(java.io.IOException) IOException(java.io.IOException)

Example 70 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project cdap by caskdata.

the class AppFabricClient method getServiceInstances.

public ServiceInstances getServiceInstances(String namespaceId, String applicationId, String serviceName) throws Exception {
    MockResponder responder = new MockResponder();
    String uri = String.format("%s/apps/%s/services/%s/instances", getNamespacePath(namespaceId), applicationId, serviceName);
    HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri);
    programLifecycleHttpHandler.getServiceInstances(request, responder, namespaceId, applicationId, serviceName);
    verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Get service instances failed");
    return responder.decodeResponseContent(ServiceInstances.class);
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest)

Aggregations

DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)115 HttpRequest (io.netty.handler.codec.http.HttpRequest)81 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)53 Test (org.junit.Test)51 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)44 HttpMethod (io.netty.handler.codec.http.HttpMethod)23 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)20 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)18 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)16 HttpContent (io.netty.handler.codec.http.HttpContent)13 HttpObject (io.netty.handler.codec.http.HttpObject)13 DefaultHttpContent (io.netty.handler.codec.http.DefaultHttpContent)12 ByteBuf (io.netty.buffer.ByteBuf)11 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)11 Test (org.junit.jupiter.api.Test)10 Channel (io.netty.channel.Channel)9 ArrayList (java.util.ArrayList)9 Nettys4Test (org.jocean.http.util.Nettys4Test)9 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)8 DisposableWrapper (org.jocean.idiom.DisposableWrapper)6