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