Search in sources :

Example 11 with HttpRequest

use of io.cdap.common.http.HttpRequest in project cdap by caskdata.

the class DataPipelineServiceTest method addConnection.

private void addConnection(String connection, ConnectionCreationRequest creationRequest) throws IOException {
    URL validatePipelineURL = serviceURI.resolve(String.format("v1/contexts/%s/connections/%s", NamespaceId.DEFAULT.getNamespace(), connection)).toURL();
    HttpRequest request = HttpRequest.builder(HttpMethod.PUT, validatePipelineURL).withBody(GSON.toJson(creationRequest)).build();
    HttpResponse response = HttpRequests.execute(request, new DefaultHttpRequestConfig(false));
    Assert.assertEquals(200, response.getResponseCode());
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) HttpResponse(io.cdap.common.http.HttpResponse) URL(java.net.URL)

Example 12 with HttpRequest

use of io.cdap.common.http.HttpRequest in project cdap by caskdata.

the class DataPipelineServiceTest method testValidatePipelineBadPipelineArtifact.

@Test
public void testValidatePipelineBadPipelineArtifact() throws IOException {
    ETLBatchConfig config = ETLBatchConfig.builder().addStage(new ETLStage("src", MockSource.getPlugin("dummy1"))).addStage(new ETLStage("sink", MockSink.getPlugin("dummy2"))).addConnection("src", "sink").build();
    ArtifactSummary badArtifact = new ArtifactSummary("ghost", "1.0.0");
    AppRequest<ETLBatchConfig> appRequest = new AppRequest<>(badArtifact, config);
    URL validatePipelineURL = serviceURI.resolve(String.format("v1/contexts/%s/validations/pipeline", NamespaceId.DEFAULT.getNamespace())).toURL();
    HttpRequest request = HttpRequest.builder(HttpMethod.POST, validatePipelineURL).withBody(GSON.toJson(appRequest)).build();
    HttpResponse response = HttpRequests.execute(request, new DefaultHttpRequestConfig(false));
    Assert.assertEquals(400, response.getResponseCode());
}
Also used : ETLBatchConfig(io.cdap.cdap.etl.proto.v2.ETLBatchConfig) HttpRequest(io.cdap.common.http.HttpRequest) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ETLStage(io.cdap.cdap.etl.proto.v2.ETLStage) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) HttpResponse(io.cdap.common.http.HttpResponse) URL(java.net.URL) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 13 with HttpRequest

use of io.cdap.common.http.HttpRequest in project cdap by caskdata.

the class DataPipelineServiceTest method testValidatePipelineChecksNamespaceExistence.

@Test
public void testValidatePipelineChecksNamespaceExistence() throws IOException {
    ETLBatchConfig config = ETLBatchConfig.builder().addStage(new ETLStage("src", MockSource.getPlugin("dummy1"))).addStage(new ETLStage("sink", MockSink.getPlugin("dummy2"))).addConnection("src", "sink").build();
    ArtifactSummary badArtifact = new ArtifactSummary("ghost", "1.0.0");
    AppRequest<ETLBatchConfig> appRequest = new AppRequest<>(badArtifact, config);
    URL validatePipelineURL = serviceURI.resolve("v1/contexts/ghost/validations/pipeline").toURL();
    HttpRequest request = HttpRequest.builder(HttpMethod.POST, validatePipelineURL).withBody(GSON.toJson(appRequest)).build();
    HttpResponse response = HttpRequests.execute(request, new DefaultHttpRequestConfig(false));
    Assert.assertEquals(404, response.getResponseCode());
}
Also used : ETLBatchConfig(io.cdap.cdap.etl.proto.v2.ETLBatchConfig) HttpRequest(io.cdap.common.http.HttpRequest) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ETLStage(io.cdap.cdap.etl.proto.v2.ETLStage) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) HttpResponse(io.cdap.common.http.HttpResponse) URL(java.net.URL) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 14 with HttpRequest

use of io.cdap.common.http.HttpRequest in project cdap by caskdata.

the class DataPipelineServiceTest method sendRequest.

private StageValidationResponse sendRequest(StageValidationRequest requestBody) throws IOException {
    URL validatePipelineURL = serviceURI.resolve(String.format("v1/contexts/%s/validations/stage", NamespaceId.DEFAULT.getNamespace())).toURL();
    HttpRequest request = HttpRequest.builder(HttpMethod.POST, validatePipelineURL).withBody(GSON.toJson(requestBody)).build();
    HttpResponse response = HttpRequests.execute(request, new DefaultHttpRequestConfig(false));
    Assert.assertEquals(200, response.getResponseCode());
    return GSON.fromJson(response.getResponseBodyAsString(), StageValidationResponse.class);
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) HttpResponse(io.cdap.common.http.HttpResponse) URL(java.net.URL)

Example 15 with HttpRequest

use of io.cdap.common.http.HttpRequest in project cdap by caskdata.

the class DatasetServiceTestBase method deployModuleBundled.

// creates a bundled jar with moduleClass and list of bundleEmbeddedJar files, moduleName and moduleClassName are
// used to make request for deploying module.
protected int deployModuleBundled(String moduleName, String moduleClassName, Class moduleClass, Location... bundleEmbeddedJars) throws IOException {
    Location moduleJar = createModuleJar(moduleClass, bundleEmbeddedJars);
    HttpRequest request = HttpRequest.put(getUrl("/data/modules/" + moduleName)).addHeader("X-Class-Name", moduleClassName).withBody((ContentProvider<? extends InputStream>) moduleJar::getInputStream).build();
    return HttpRequests.execute(request, REQUEST_CONFIG).getResponseCode();
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) ContentProvider(io.cdap.common.ContentProvider) InputStream(java.io.InputStream) Location(org.apache.twill.filesystem.Location)

Aggregations

HttpRequest (io.cdap.common.http.HttpRequest)124 HttpResponse (io.cdap.common.http.HttpResponse)92 URL (java.net.URL)81 Test (org.junit.Test)33 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)14 IOException (java.io.IOException)14 AccessToken (io.cdap.cdap.security.authentication.client.AccessToken)13 DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)10 BadRequestException (io.cdap.cdap.common.BadRequestException)9 NotFoundException (io.cdap.cdap.common.NotFoundException)8 TopicNotFoundException (io.cdap.cdap.api.messaging.TopicNotFoundException)5 ServiceManager (io.cdap.cdap.test.ServiceManager)5 TypeToken (com.google.gson.reflect.TypeToken)4 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)4 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)4 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)4 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)4 TopicId (io.cdap.cdap.proto.id.TopicId)4 ApplicationManager (io.cdap.cdap.test.ApplicationManager)4 ByteBuffer (java.nio.ByteBuffer)4