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