Search in sources :

Example 11 with DatasetInstanceConfiguration

use of io.cdap.cdap.proto.DatasetInstanceConfiguration in project cdap by caskdata.

the class DatasetInstanceServiceTest method testInstanceMetaCache.

@Test
public void testInstanceMetaCache() throws Exception {
    // deploy a dataset
    instanceService.create(NamespaceId.DEFAULT.getEntityName(), "testds", new DatasetInstanceConfiguration("table", new HashMap<>()));
    // get the dataset meta for two different owners, assert it is the same
    DatasetMeta meta = instanceService.get(NamespaceId.DEFAULT.dataset("testds"));
    DatasetMeta met2 = instanceService.get(NamespaceId.DEFAULT.dataset("testds"));
    Assert.assertSame(meta, met2);
    // update the dataset
    instanceService.update(NamespaceId.DEFAULT.dataset("testds"), ImmutableMap.of("ttl", "12345678"));
    // get the dataset meta, validate it changed
    met2 = instanceService.get(NamespaceId.DEFAULT.dataset("testds"));
    Assert.assertNotSame(meta, met2);
    Assert.assertEquals("12345678", met2.getSpec().getProperty("ttl"));
    // delete the dataset
    instanceService.drop(NamespaceId.DEFAULT.dataset("testds"));
    // get the dataset meta, validate not found
    try {
        instanceService.get(NamespaceId.DEFAULT.dataset("testds"));
        Assert.fail("get() should have thrown NotFoundException");
    } catch (NotFoundException e) {
    // expected
    }
    // recreate the dataset
    instanceService.create(NamespaceId.DEFAULT.getNamespace(), "testds", new DatasetInstanceConfiguration("table", new HashMap<>()));
    // get the dataset meta, validate it is up to date
    met2 = instanceService.get(NamespaceId.DEFAULT.dataset("testds"));
    Assert.assertEquals(meta.getSpec(), met2.getSpec());
}
Also used : HashMap(java.util.HashMap) DatasetMeta(io.cdap.cdap.proto.DatasetMeta) NotFoundException(io.cdap.cdap.common.NotFoundException) DatasetInstanceConfiguration(io.cdap.cdap.proto.DatasetInstanceConfiguration) Test(org.junit.Test)

Example 12 with DatasetInstanceConfiguration

use of io.cdap.cdap.proto.DatasetInstanceConfiguration in project cdap by caskdata.

the class CreateDatasetInstanceCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String datasetType = arguments.get(ArgumentName.DATASET_TYPE.toString());
    String datasetName = arguments.get(ArgumentName.NEW_DATASET.toString());
    String datasetPropertiesString = arguments.getOptional(ArgumentName.DATASET_PROPERTIES.toString(), "");
    String datasetDescription = arguments.getOptional(ArgumentName.DATASET_DESCRIPTON.toString(), null);
    Map<String, String> datasetProperties = ArgumentParser.parseMap(datasetPropertiesString, ArgumentName.DATASET_PROPERTIES.toString());
    String datasetOwner = arguments.getOptional(ArgumentName.PRINCIPAL.toString(), null);
    // TODO: CDAP-8110 (Rohit) Support owner principal in CLI by deprecating this command and introducing a more user
    // friendly create dataset instance command
    DatasetInstanceConfiguration datasetConfig = new DatasetInstanceConfiguration(datasetType, datasetProperties, datasetDescription, datasetOwner);
    datasetClient.create(cliConfig.getCurrentNamespace().dataset(datasetName), datasetConfig);
    StringBuilder builder = new StringBuilder(String.format("Successfully created dataset named '%s' with type " + "'%s', properties '%s'", datasetName, datasetType, GSON.toJson(datasetProperties)));
    if (datasetDescription != null) {
        builder.append(String.format(", description '%s'", datasetDescription));
    }
    if (datasetOwner != null) {
        builder.append(String.format(", owner principal '%s'", datasetOwner));
    }
    output.printf(builder.toString());
    output.println();
}
Also used : DatasetInstanceConfiguration(io.cdap.cdap.proto.DatasetInstanceConfiguration)

Aggregations

DatasetInstanceConfiguration (io.cdap.cdap.proto.DatasetInstanceConfiguration)12 Test (org.junit.Test)6 DatasetId (io.cdap.cdap.proto.id.DatasetId)4 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)3 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)3 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)2 Table (io.cdap.cdap.api.dataset.table.Table)2 DatasetTypeNotFoundException (io.cdap.cdap.common.DatasetTypeNotFoundException)2 DatasetMeta (io.cdap.cdap.proto.DatasetMeta)2 MetadataSearchResponse (io.cdap.cdap.proto.metadata.MetadataSearchResponse)2 HashMap (java.util.HashMap)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)1 InstanceConflictException (io.cdap.cdap.api.dataset.InstanceConflictException)1 StandaloneDataset (io.cdap.cdap.client.app.StandaloneDataset)1 StandaloneDatasetModule (io.cdap.cdap.client.app.StandaloneDatasetModule)1 BadRequestException (io.cdap.cdap.common.BadRequestException)1 DatasetAlreadyExistsException (io.cdap.cdap.common.DatasetAlreadyExistsException)1 DatasetModuleNotFoundException (io.cdap.cdap.common.DatasetModuleNotFoundException)1 HandlerException (io.cdap.cdap.common.HandlerException)1