Search in sources :

Example 26 with DefaultHttpRequest

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

the class AppFabricClient method getVersionedInfo.

public ApplicationDetail getVersionedInfo(ApplicationId appId) throws Exception {
    HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, String.format("%s/apps/%s/versions/%s", getNamespacePath(appId.getNamespace()), appId.getApplication(), appId.getVersion()));
    request.headers().set(Constants.Gateway.API_KEY, "api-key-example");
    MockResponder mockResponder = new MockResponder();
    appLifecycleHttpHandler.getAppVersionInfo(request, mockResponder, appId.getNamespace(), appId.getApplication(), appId.getVersion());
    verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Getting app version info failed");
    return mockResponder.decodeResponseContent(new TypeToken<ApplicationDetail>() {
    }.getType(), 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) TypeToken(com.google.gson.reflect.TypeToken)

Example 27 with DefaultHttpRequest

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

the class AppFabricClient method deployApplication.

public void deployApplication(ApplicationId appId, AppRequest appRequest) throws Exception {
    HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, String.format("%s/apps/%s/versions/%s/create", getNamespacePath(appId.getNamespace()), appId.getApplication(), appId.getVersion()));
    request.headers().set(Constants.Gateway.API_KEY, "api-key-example");
    HttpUtil.setTransferEncodingChunked(request, true);
    MockResponder mockResponder = new MockResponder();
    BodyConsumer bodyConsumer = appLifecycleHttpHandler.createAppVersion(request, mockResponder, appId.getNamespace(), appId.getApplication(), appId.getVersion());
    Preconditions.checkNotNull(bodyConsumer, "BodyConsumer from deploy call should not be null");
    bodyConsumer.chunk(Unpooled.copiedBuffer(GSON.toJson(appRequest), StandardCharsets.UTF_8), mockResponder);
    bodyConsumer.finished(mockResponder);
    verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Failed to deploy app");
}
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) BodyConsumer(co.cask.http.BodyConsumer)

Example 28 with DefaultHttpRequest

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

the class AppFabricClient method getPlugins.

public List<PluginInstanceDetail> getPlugins(ApplicationId application) throws Exception {
    HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, String.format("%s/apps/%s", getNamespacePath(application.getNamespace()), application.getApplication()));
    request.headers().set(Constants.Gateway.API_KEY, "api-key-example");
    MockResponder mockResponder = new MockResponder();
    appLifecycleHttpHandler.getPluginsInfo(request, mockResponder, application.getNamespace(), application.getApplication());
    verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Getting app info failed");
    return mockResponder.decodeResponseContent(new TypeToken<List<PluginInstanceDetail>>() {
    }.getType(), 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) TypeToken(com.google.gson.reflect.TypeToken) PluginInstanceDetail(co.cask.cdap.proto.PluginInstanceDetail)

Example 29 with DefaultHttpRequest

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

the class AppFabricClient method getWorkerInstances.

public Instances getWorkerInstances(String namespaceId, String appId, String workerId) throws Exception {
    MockResponder responder = new MockResponder();
    String uri = String.format("%s/apps/%s/worker/%s/instances", getNamespacePath(namespaceId), appId, workerId);
    HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri);
    programLifecycleHttpHandler.getWorkerInstances(request, responder, namespaceId, appId, workerId);
    verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Get worker instances failed");
    return responder.decodeResponseContent(Instances.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)

Example 30 with DefaultHttpRequest

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

the class AppFabricClient method getInfo.

public ApplicationDetail getInfo(ApplicationId appId) throws Exception {
    HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, String.format("%s/apps/%s", getNamespacePath(appId.getNamespace()), appId.getApplication()));
    request.headers().set(Constants.Gateway.API_KEY, "api-key-example");
    MockResponder mockResponder = new MockResponder();
    appLifecycleHttpHandler.getAppInfo(request, mockResponder, appId.getNamespace(), appId.getApplication());
    verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Getting app info failed");
    return mockResponder.decodeResponseContent(new TypeToken<ApplicationDetail>() {
    }.getType(), 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) TypeToken(com.google.gson.reflect.TypeToken)

Aggregations

DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)111 HttpRequest (io.netty.handler.codec.http.HttpRequest)79 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)52 Test (org.junit.Test)51 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)43 HttpMethod (io.netty.handler.codec.http.HttpMethod)23 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)18 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 Nettys4Test (org.jocean.http.util.Nettys4Test)9 ArrayList (java.util.ArrayList)8 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)7 DisposableWrapper (org.jocean.idiom.DisposableWrapper)6