...
Code Block |
---|
ClientConfig clientConfig; // Construct the client used to interact with CDAP ProgramClient programClient = new ProgramClient(clientConfig); // Start a service in the WordCount example programClient.start(NamespaceId.DEFAULT.app("WordCount").service("RetrieveCounts")); // formatted in JSON programClient.getLiveInfo(NamespaceId.DEFAULT.app("SportResults").service("UploadService")); // Fetch program logs in the WordCount example programClient.getProgramLogs(NamespaceId.DEFAULT.app("WordCount").service("RetrieveCounts"), 0, Long.MAX_VALUE); // Scale a service in the SportResults example programClient.setServiceInstances(NamespaceId.DEFAULT.app("SportResults").service("UploadService"), 3); // Stop a service in the SportResults example programClient.stop(NamespaceId.DEFAULT.app("SportResults").service("UploadService")); |
QueryClient
Code Block |
---|
ClientConfig clientConfig;
// Construct the client used to interact with CDAP
QueryClient queryClient = new QueryClient(clientConfig);
// Perform an ad-hoc query using the Purchase example
ListenableFuture<ExploreExecutionResult> resultFuture = queryClient.execute(NamespaceId.DEFAULT, "SELECT * FROM dataset_history WHERE customer IN ('Alice','Bob')");
ExploreExecutionResult results = resultFuture.get();
// Fetch schema
List<ColumnDesc> schema = results.getResultSchema();
String[] header = new String[schema.size()];
for (int i = 0; i < header.length; i++) {
ColumnDesc column = schema.get(i);
// Hive columns start at 1
int index = column.getPosition() - 1;
header[index] = column.getName() + ": " + column.getType();
}
|
ServiceClient
Code Block |
---|
ClientConfig clientConfig; // Construct the client used to interact with CDAP ServiceClient serviceClient = new ServiceClient(clientConfig); // Fetch service information using the service in the PurchaseApp example ServiceSpecification serviceSpec = serviceClient.get(NamespaceId.DEFAULT.app("PurchaseApp").service("CatalogLookup")); |
...