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