Search in sources :

Example 71 with HttpRequest

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

the class RemoteSecureStore method put.

@Override
public void put(String namespace, String name, String data, @Nullable String description, Map<String, String> properties) throws Exception {
    SecureKeyCreateRequest createRequest = new SecureKeyCreateRequest(description, data, properties);
    HttpRequest request = remoteClient.requestBuilder(HttpMethod.PUT, createPath(namespace, name)).withBody(GSON.toJson(createRequest)).build();
    HttpResponse response = remoteClient.execute(request);
    handleResponse(response, namespace, name, String.format("Error occurred while putting key %s:%s", namespace, name));
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) SecureKeyCreateRequest(io.cdap.cdap.proto.security.SecureKeyCreateRequest) HttpResponse(io.cdap.common.http.HttpResponse)

Example 72 with HttpRequest

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

the class RemoteSecureStore method list.

@Override
public List<SecureStoreMetadata> list(String namespace) throws Exception {
    HttpRequest request = remoteClient.requestBuilder(HttpMethod.GET, createPath(namespace)).build();
    HttpResponse response = remoteClient.execute(request);
    handleResponse(response, namespace, "", "Error occurred while listing keys");
    return GSON.fromJson(response.getResponseBodyAsString(), LIST_TYPE);
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse)

Example 73 with HttpRequest

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

the class RemoteSecureStore method delete.

@Override
public void delete(String namespace, String name) throws Exception {
    HttpRequest request = remoteClient.requestBuilder(HttpMethod.DELETE, createPath(namespace, name)).build();
    HttpResponse response = remoteClient.execute(request);
    handleResponse(response, namespace, name, String.format("Error occurred while deleting key %s:%s", namespace, name));
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse)

Example 74 with HttpRequest

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

the class DataPipelineTest method testServiceUrl.

private void testServiceUrl(Engine engine) throws Exception {
    // Deploy the ServiceApp application
    ApplicationManager appManager = deployApplication(ServiceApp.class);
    // Start Greeting service and use it
    ServiceManager serviceManager = appManager.getServiceManager(ServiceApp.Name.SERVICE_NAME).start();
    // Wait service startup
    serviceManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS);
    URL url = new URL(serviceManager.getServiceURL(), "name");
    HttpRequest httpRequest = HttpRequest.post(url).withBody("bob").build();
    HttpResponse httpResponse = HttpRequests.execute(httpRequest, new DefaultHttpRequestConfig(false));
    Assert.assertEquals(HttpURLConnection.HTTP_OK, httpResponse.getResponseCode());
    url = new URL(serviceManager.getServiceURL(), "name/bob");
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    Assert.assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
    String response;
    try {
        response = new String(ByteStreams.toByteArray(connection.getInputStream()), Charsets.UTF_8);
    } finally {
        connection.disconnect();
    }
    Assert.assertEquals("bob", response);
    String sourceName = "ServiceUrlInput-" + engine.name();
    String sinkName = "ServiceUrlOutput-" + engine.name();
    /*
     * source --> filter --> sink
     */
    ETLBatchConfig etlConfig = ETLBatchConfig.builder().setEngine(engine).addStage(new ETLStage("source", MockSource.getPlugin(sourceName))).addStage(new ETLStage("filter", FilterTransform.getPlugin("name"))).addStage(new ETLStage("sink", MockSink.getPlugin(sinkName))).addConnection("source", "filter").addConnection("filter", "sink").build();
    AppRequest<ETLBatchConfig> appRequest = new AppRequest<>(APP_ARTIFACT, etlConfig);
    ApplicationId appId = NamespaceId.DEFAULT.app("ServiceUrl-" + engine);
    appManager = deployApplication(appId, appRequest);
    Schema schema = Schema.recordOf("testRecord", Schema.Field.of("name", Schema.of(Schema.Type.STRING)));
    StructuredRecord recordSamuel = StructuredRecord.builder(schema).set("name", "samuel").build();
    StructuredRecord recordBob = StructuredRecord.builder(schema).set("name", "bob").build();
    StructuredRecord recordJane = StructuredRecord.builder(schema).set("name", "jane").build();
    // write one record to each source
    DataSetManager<Table> inputManager = getDataset(NamespaceId.DEFAULT.dataset(sourceName));
    MockSource.writeInput(inputManager, ImmutableList.of(recordSamuel, recordBob, recordJane));
    WorkflowManager workflowManager = appManager.getWorkflowManager(SmartWorkflow.NAME);
    workflowManager.start();
    workflowManager.waitForRun(ProgramRunStatus.COMPLETED, 5, TimeUnit.MINUTES);
    // check output
    DataSetManager<Table> sinkManager = getDataset(sinkName);
    Set<StructuredRecord> expected = ImmutableSet.of(recordBob);
    Set<StructuredRecord> actual = Sets.newHashSet(MockSink.readOutput(sinkManager));
    Assert.assertEquals(expected, actual);
    serviceManager.stop();
    serviceManager.waitForRun(ProgramRunStatus.KILLED, 180, TimeUnit.SECONDS);
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) ApplicationManager(io.cdap.cdap.test.ApplicationManager) Table(io.cdap.cdap.api.dataset.table.Table) KeyValueTable(io.cdap.cdap.api.dataset.lib.KeyValueTable) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) Schema(io.cdap.cdap.api.data.schema.Schema) WorkflowManager(io.cdap.cdap.test.WorkflowManager) HttpResponse(io.cdap.common.http.HttpResponse) URL(java.net.URL) StructuredRecord(io.cdap.cdap.api.data.format.StructuredRecord) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) ETLBatchConfig(io.cdap.cdap.etl.proto.v2.ETLBatchConfig) HttpURLConnection(java.net.HttpURLConnection) ETLStage(io.cdap.cdap.etl.proto.v2.ETLStage) ServiceManager(io.cdap.cdap.test.ServiceManager) ApplicationId(io.cdap.cdap.proto.id.ApplicationId)

Example 75 with HttpRequest

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

the class DefaultMetadataServiceClient method update.

@Override
public void update(MetadataMutation.Update updateMutation) {
    HttpRequest request = remoteClient.requestBuilder(HttpMethod.POST, "metadata-internals/update").withBody(GSON.toJson(updateMutation)).build();
    HttpResponse response = execute(request);
    if (HttpResponseStatus.OK.code() != response.getResponseCode()) {
        LOG.trace("Failed to update metadata for entity %s: %s", updateMutation.getEntity(), response);
    }
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse)

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