use of co.cask.cdap.proto.DatasetInstanceConfiguration in project cdap by caskdata.
the class ConversionHelpers method getInstanceConfiguration.
static DatasetInstanceConfiguration getInstanceConfiguration(HttpRequest request) throws BadRequestException {
Reader reader = new InputStreamReader(new ChannelBufferInputStream(request.getContent()), Charsets.UTF_8);
try {
DatasetInstanceConfiguration config = GSON.fromJson(reader, DatasetInstanceConfiguration.class);
Preconditions.checkNotNull(config.getTypeName(), "The typeName must be specified.");
return config;
} catch (JsonSyntaxException | NullPointerException e) {
throw new BadRequestException(e.getMessage());
}
}
use of co.cask.cdap.proto.DatasetInstanceConfiguration in project cdap by caskdata.
the class DatasetInstanceHandlerTest method createInstance.
private HttpResponse createInstance(DatasetId instance, String typeName, @Nullable String description, @Nullable DatasetProperties props, @Nullable String ownerPrincipal) throws IOException {
DatasetInstanceConfiguration creationProperties;
if (props != null) {
creationProperties = new DatasetInstanceConfiguration(typeName, props.getProperties(), description, ownerPrincipal);
} else {
creationProperties = new DatasetInstanceConfiguration(typeName, null, description, ownerPrincipal);
}
HttpRequest request = HttpRequest.put(getUrl(instance.getNamespace(), "/data/datasets/" + instance.getEntityName())).withBody(GSON.toJson(creationProperties)).build();
return HttpRequests.execute(request);
}
use of co.cask.cdap.proto.DatasetInstanceConfiguration in project cdap by caskdata.
the class DatasetTypeHandlerTest method testBasics.
@Test
public void testBasics() throws Exception {
// nothing has been deployed, modules and types list is empty
verifyAll(NO_MODULES, NO_DEPENDENCIES);
// deploy module and verify that it can be retrieved in all ways
Assert.assertEquals(HttpStatus.SC_OK, deployModule("module1", TestModule1x.class).getResponseCode());
verifyAll(ONLY_MODULE1X, ONLY_1X_DEPENDENCIES);
// cannot deploy other module with same types
Assert.assertEquals(HttpStatus.SC_CONFLICT, deployModule("not-module1", TestModule1.class).getResponseCode());
verifyAll(ONLY_MODULE1X, ONLY_1X_DEPENDENCIES);
// can deploy same module again
Assert.assertEquals(HttpStatus.SC_OK, deployModule("module1", TestModule1x.class).getResponseCode());
verifyAll(ONLY_MODULE1X, ONLY_1X_DEPENDENCIES);
// create a dataset instance, verify that we cannot redeploy the module with fewer types, even with force option
instanceService.create(NamespaceId.DEFAULT.getNamespace(), "instance1x", new DatasetInstanceConfiguration("datasetType1x", new HashMap<String, String>()));
Assert.assertEquals(HttpStatus.SC_CONFLICT, deployModule("module1", TestModule1.class).getResponseCode());
Assert.assertEquals(HttpStatus.SC_CONFLICT, deployModule("module1", TestModule1.class, true).getResponseCode());
verifyAll(ONLY_MODULE1X, ONLY_1X_DEPENDENCIES);
// drop the instance, now we should be able to redeploy, dropping type1x
instanceService.drop(NamespaceId.DEFAULT.dataset("instance1x"));
Assert.assertEquals(HttpStatus.SC_OK, deployModule("module1", TestModule1.class).getResponseCode());
verifyAll(ONLY_MODULE1, ONLY_1_DEPENDENCIES);
// redeploy module with more types and validate
Assert.assertEquals(HttpStatus.SC_OK, deployModule("module1", TestModule1x.class).getResponseCode());
verifyAll(ONLY_MODULE1X, ONLY_1X_DEPENDENCIES);
// deploy another module which depends on the first one
Assert.assertEquals(HttpStatus.SC_OK, deployModule("module2", TestModule2.class).getResponseCode());
verifyAll(MODULES_1X_AND_2, BOTH_1X_2_DEPENDENCIES);
// cannot delete non-existent module
Assert.assertEquals(HttpStatus.SC_NOT_FOUND, deleteModule("non-existing-module").getResponseCode());
// cannot delete module1 since module2 depends on it, verify that nothing has been deleted
Assert.assertEquals(HttpStatus.SC_CONFLICT, deleteModule("module1").getResponseCode());
verifyAll(MODULES_1X_AND_2, BOTH_1X_2_DEPENDENCIES);
// cannot deploy same module again with fewer types (because module2 depends on it)
Assert.assertEquals(HttpStatus.SC_CONFLICT, deployModule("module1", TestModule1.class).getResponseCode());
verifyAll(MODULES_1X_AND_2, BOTH_1X_2_DEPENDENCIES);
// create dataset instances, try force deploy of same module again with fewer types - should fail
instanceService.create(NamespaceId.DEFAULT.getNamespace(), "instance1", new DatasetInstanceConfiguration("datasetType1", new HashMap<String, String>()));
instanceService.create(NamespaceId.DEFAULT.getNamespace(), "instance1x", new DatasetInstanceConfiguration("datasetType1x", new HashMap<String, String>()));
Assert.assertEquals(HttpStatus.SC_CONFLICT, deployModule("module1", TestModule1.class, true).getResponseCode());
verifyAll(MODULES_1X_AND_2, BOTH_1X_2_DEPENDENCIES);
// drop the instance of type1x, now forced deploy should work
instanceService.drop(NamespaceId.DEFAULT.dataset("instance1x"));
Assert.assertEquals(HttpStatus.SC_OK, deployModule("module1", TestModule1.class, true).getResponseCode());
verifyAll(MODULES_1_AND_2, BOTH_1_2_DEPENDENCIES);
// delete module2, should be removed from usedBy list everywhere and all its types should no longer be available
Assert.assertEquals(HttpStatus.SC_OK, deleteModule("module2").getResponseCode());
Assert.assertEquals(HttpStatus.SC_NOT_FOUND, getMissingType("datasetType2").getResponseCode());
verifyAll(ONLY_MODULE1, ONLY_1_DEPENDENCIES);
// cannot delete module2 again
Assert.assertEquals(HttpStatus.SC_NOT_FOUND, deleteModule("module2").getResponseCode());
// cannot delete module 1 becuse there is an instance
Assert.assertEquals(HttpStatus.SC_CONFLICT, deleteModules().getResponseCode());
verifyAll(ONLY_MODULE1, ONLY_1_DEPENDENCIES);
// drop the instance of type1, now delete of module1 should work
instanceService.drop(NamespaceId.DEFAULT.dataset("instance1"));
Assert.assertEquals(HttpStatus.SC_OK, deleteModules().getResponseCode());
Assert.assertEquals(HttpStatus.SC_NOT_FOUND, getMissingType("datasetType1").getResponseCode());
verifyAll(NO_MODULES, NO_DEPENDENCIES);
}
use of co.cask.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<String, String>()));
// get the dataset meta for two different owners, assert it is the same
DatasetMeta meta = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app1", ProgramType.FLOW, "flow1")));
DatasetMeta met2 = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app2", ProgramType.FLOW, "flow2")));
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"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app2", ProgramType.FLOW, "flow2")));
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"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app1", ProgramType.FLOW, "flow2")));
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<String, String>()));
// get the dataset meta, validate it is up to date
met2 = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app2", ProgramType.FLOW, "flow2")));
Assert.assertEquals(meta.getSpec(), met2.getSpec());
}
use of co.cask.cdap.proto.DatasetInstanceConfiguration in project cdap by caskdata.
the class IntegrationTestManager method addDatasetInstance.
@Override
public <T extends DatasetAdmin> T addDatasetInstance(String datasetType, DatasetId datasetId, DatasetProperties props) throws Exception {
DatasetInstanceConfiguration dsConf = new DatasetInstanceConfiguration(datasetType, props.getProperties(), props.getDescription(), null);
datasetClient.create(datasetId, dsConf);
return (T) new RemoteDatasetAdmin(datasetClient, datasetId, dsConf);
}
Aggregations