Search in sources :

Example 1 with DatasetTypeClient

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()));
}
Also used : DatasetTypeClient(io.cdap.cdap.client.DatasetTypeClient) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta)

Example 2 with DatasetTypeClient

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");
}
Also used : DatasetTypeClient(io.cdap.cdap.client.DatasetTypeClient) DatasetTypeId(io.cdap.cdap.proto.id.DatasetTypeId) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceClient(io.cdap.cdap.client.NamespaceClient) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) DatasetTypeNotFoundException(io.cdap.cdap.common.DatasetTypeNotFoundException) FakeDataset(io.cdap.cdap.client.app.FakeDataset) Test(org.junit.Test)

Aggregations

DatasetTypeClient (io.cdap.cdap.client.DatasetTypeClient)2 DatasetTypeMeta (io.cdap.cdap.proto.DatasetTypeMeta)2 NamespaceClient (io.cdap.cdap.client.NamespaceClient)1 FakeDataset (io.cdap.cdap.client.app.FakeDataset)1 DatasetTypeNotFoundException (io.cdap.cdap.common.DatasetTypeNotFoundException)1 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)1 DatasetTypeId (io.cdap.cdap.proto.id.DatasetTypeId)1 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)1 Test (org.junit.Test)1