Search in sources :

Example 51 with DefaultHttpRequest

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

the class AppFabricClient method getPlugins.

public List<PluginInstanceDetail> getPlugins(ApplicationId application) throws Exception {
    DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, String.format("%s/apps/%s", getNamespacePath(application.getNamespace()), application.getApplication()));
    request.setHeader(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 : DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) TypeToken(com.google.gson.reflect.TypeToken) PluginInstanceDetail(co.cask.cdap.proto.PluginInstanceDetail)

Example 52 with DefaultHttpRequest

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

the class AppFabricClient method deleteAllApplications.

public void deleteAllApplications(NamespaceId namespaceId) throws Exception {
    DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.DELETE, String.format("%s/apps", getNamespacePath(namespaceId.getNamespace())));
    request.setHeader(Constants.Gateway.API_KEY, "api-key-example");
    MockResponder mockResponder = new MockResponder();
    appLifecycleHttpHandler.deleteAllApps(request, mockResponder, namespaceId.getNamespace());
    verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Deleting all apps failed");
}
Also used : DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest)

Example 53 with DefaultHttpRequest

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

the class AppFabricClient method getWorkflowToken.

public WorkflowTokenDetail getWorkflowToken(String namespaceId, String appId, String wflowId, String runId, @Nullable WorkflowToken.Scope scope, @Nullable String key) throws NotFoundException {
    MockResponder responder = new MockResponder();
    String uri = String.format("%s/apps/%s/workflows/%s/runs/%s/token", getNamespacePath(namespaceId), appId, wflowId, runId);
    HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri);
    scope = scope == null ? WorkflowToken.Scope.USER : scope;
    key = key == null ? "" : key;
    workflowHttpHandler.getWorkflowToken(request, responder, namespaceId, appId, wflowId, runId, scope.name(), key);
    Type workflowTokenDetailType = new TypeToken<WorkflowTokenDetail>() {
    }.getType();
    WorkflowTokenDetail workflowTokenDetail = responder.decodeResponseContent(workflowTokenDetailType, GSON);
    verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Getting workflow token failed");
    return workflowTokenDetail;
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) ProgramType(co.cask.cdap.proto.ProgramType) Type(java.lang.reflect.Type) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) WorkflowTokenDetail(co.cask.cdap.proto.WorkflowTokenDetail)

Example 54 with DefaultHttpRequest

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

the class AppFabricClient method getHistory.

public List<RunRecord> getHistory(Id.Program programId, ProgramRunStatus status) throws Exception {
    String namespaceId = programId.getNamespaceId();
    String appId = programId.getApplicationId();
    String programName = programId.getId();
    String categoryName = programId.getType().getCategoryName();
    MockResponder responder = new MockResponder();
    String uri = String.format("%s/apps/%s/%s/%s/runs?status=" + status.name(), getNamespacePath(namespaceId), appId, categoryName, programName);
    HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri);
    programLifecycleHttpHandler.programHistory(request, responder, namespaceId, appId, categoryName, programName, status.name(), null, null, 100);
    verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Getting workflow history failed");
    return responder.decodeResponseContent(RUN_RECORDS_TYPE);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest)

Example 55 with DefaultHttpRequest

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

the class AppFabricClient method deployApplication.

public void deployApplication(ApplicationId appId, AppRequest appRequest) throws Exception {
    DefaultHttpRequest requst = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, String.format("%s/apps/%s/versions/%s/create", getNamespacePath(appId.getNamespace()), appId.getApplication(), appId.getVersion()));
    createApplication(appId, requst, appRequest);
}
Also used : DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest)

Aggregations

DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)128 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)101 Test (org.junit.Test)53 Channel (org.jboss.netty.channel.Channel)37 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)33 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)25 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)24 Test (org.testng.annotations.Test)23 HttpMethod (org.jboss.netty.handler.codec.http.HttpMethod)21 ChannelFuture (org.jboss.netty.channel.ChannelFuture)19 SimpleHttpResponseHandler (com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler)12 SimpleTestHttpClient (com.linkedin.databus.core.test.netty.SimpleTestHttpClient)12 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)11 InetSocketAddress (java.net.InetSocketAddress)11 Logger (org.apache.log4j.Logger)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)10 SucceededChannelFuture (org.jboss.netty.channel.SucceededChannelFuture)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 SocketAddress (java.net.SocketAddress)9