use of io.cdap.cdap.client.DatasetTypeClient in project cdap by caskdata.
the class GenerateClientUsageExample method datasetTypeClient.
public void datasetTypeClient() throws Exception {
// Construct the client used to interact with CDAP
DatasetTypeClient datasetTypeClient = new DatasetTypeClient(clientConfig);
// Fetch the dataset type information using the type name
DatasetTypeMeta datasetTypeMeta = datasetTypeClient.get(NamespaceId.DEFAULT.datasetType("someDatasetType"));
// Fetch the dataset type information using the classname
datasetTypeClient.get(NamespaceId.DEFAULT.datasetType(SomeDataset.class.getName()));
}
use of io.cdap.cdap.client.DatasetTypeClient in project cdap by caskdata.
the class CLITestBase method testDataset.
@Test
public void testDataset() throws Exception {
String datasetName = PREFIX + "sdf123lkj";
String ownedDatasetName = PREFIX + "owned";
CLIConfig cliConfig = getCliConfig();
DatasetTypeClient datasetTypeClient = new DatasetTypeClient(cliConfig.getClientConfig());
DatasetTypeMeta datasetType = datasetTypeClient.list(NamespaceId.DEFAULT).get(0);
testCommandOutputContains("create dataset instance " + datasetType.getName() + " " + datasetName + " \"a=1\"", "Successfully created dataset");
testCommandOutputContains("list dataset instances", FakeDataset.class.getSimpleName());
testCommandOutputContains("get dataset instance properties " + datasetName, "a,1");
// test dataset creation with owner
String commandOutput = getCommandOutput("create dataset instance " + datasetType.getName() + " " + ownedDatasetName + " \"a=1\"" + " " + "someDescription " + ArgumentName.PRINCIPAL + " alice/somehost.net@somekdc.net");
Assert.assertTrue(commandOutput.contains("Successfully created dataset"));
Assert.assertTrue(commandOutput.contains("alice/somehost.net@somekdc.net"));
// test describing the table returns the given owner information
testCommandOutputContains("describe dataset instance " + ownedDatasetName, "alice/somehost.net@somekdc.net");
NamespaceClient namespaceClient = new NamespaceClient(cliConfig.getClientConfig());
NamespaceId barspace = new NamespaceId("bar");
namespaceClient.create(new NamespaceMeta.Builder().setName(barspace).build());
cliConfig.setNamespace(barspace);
// list of dataset instances is different in 'foo' namespace
testCommandOutputNotContains("list dataset instances", FakeDataset.class.getSimpleName());
// also can not create dataset instances if the type it depends on exists only in a different namespace.
DatasetTypeId datasetType1 = barspace.datasetType(datasetType.getName());
testCommandOutputContains("create dataset instance " + datasetType.getName() + " " + datasetName, new DatasetTypeNotFoundException(datasetType1).getMessage());
testCommandOutputContains("use namespace default", "Now using namespace 'default'");
try {
testCommandOutputContains("truncate dataset instance " + datasetName, "Successfully truncated");
} finally {
testCommandOutputContains("delete dataset instance " + datasetName, "Successfully deleted");
}
String datasetName2 = PREFIX + "asoijm39485";
String description = "test-description-for-" + datasetName2;
testCommandOutputContains("create dataset instance " + datasetType.getName() + " " + datasetName2 + " \"a=1\"" + " " + description, "Successfully created dataset");
testCommandOutputContains("list dataset instances", description);
testCommandOutputContains("delete dataset instance " + datasetName2, "Successfully deleted");
testCommandOutputContains("delete dataset instance " + ownedDatasetName, "Successfully deleted");
}
Aggregations