use of io.cdap.cdap.api.dataset.IncompatibleUpdateException in project cdap by cdapio.
the class DatasetDefinitionRegistryWithDefaultModules method testCompositeDatasetReconfigure.
// tests that CompositeDatasetDefinition correctly delegates reconfigure() to its embedded types
@Test
public void testCompositeDatasetReconfigure() throws IncompatibleUpdateException {
CompositeDatasetDefinition composite = new CompositeDatasetDefinition("composite", "pedantic", new PedanticDatasetDefinition("pedantic")) {
@Override
public Dataset getDataset(DatasetContext datasetContext, DatasetSpecification spec, Map arguments, ClassLoader classLoader) {
return null;
}
};
DatasetSpecification spec = composite.configure("nn", DatasetProperties.EMPTY);
DatasetSpecification respec = composite.reconfigure("nn", DatasetProperties.EMPTY, spec);
Assert.assertEquals(spec, respec);
try {
composite.reconfigure("nn", DatasetProperties.builder().add("immutable", "x").build(), spec);
Assert.fail("reconfigure should have thrown exception");
} catch (IncompatibleUpdateException e) {
// expected
}
}
use of io.cdap.cdap.api.dataset.IncompatibleUpdateException in project cdap by cdapio.
the class DatasetAdminOpHTTPHandler method update.
@POST
@Path("/data/datasets/{name}/admin/update")
public void update(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String name) throws Exception {
propagateUserId(request);
InternalDatasetUpdateParams params = GSON.fromJson(request.content().toString(StandardCharsets.UTF_8), InternalDatasetUpdateParams.class);
Preconditions.checkArgument(params.getProperties() != null, "Missing required 'instanceProps' parameter.");
Preconditions.checkArgument(params.getTypeMeta() != null, "Missing required 'typeMeta' parameter.");
Preconditions.checkArgument(params.getExistingSpec() != null, "Missing required 'existingSpec' parameter.");
DatasetProperties props = params.getProperties();
DatasetSpecification existing = params.getExistingSpec();
DatasetTypeMeta typeMeta = params.getTypeMeta();
try {
DatasetId instanceId = new DatasetId(namespaceId, name);
DatasetCreationResponse response = datasetAdminService.createOrUpdate(instanceId, typeMeta, props, existing);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(response));
} catch (IncompatibleUpdateException e) {
throw new ConflictException(e.getMessage());
}
}
use of io.cdap.cdap.api.dataset.IncompatibleUpdateException in project cdap by caskdata.
the class DatasetInstanceCreator method createInstances.
/**
* Receives an input containing application specification and location
* and verifies both.
*
* @param namespaceId the namespace to create the dataset instance in
* @param datasets the datasets to create
* @param ownerPrincipal the principal of the owner for the datasets to be created.
* @param authorizingUser the authorizing user who will be making the call
*/
void createInstances(NamespaceId namespaceId, Map<String, DatasetCreationSpec> datasets, @Nullable final KerberosPrincipalId ownerPrincipal, String authorizingUser) throws Exception {
// create dataset instances
for (Map.Entry<String, DatasetCreationSpec> instanceEntry : datasets.entrySet()) {
String instanceName = instanceEntry.getKey();
final DatasetId instanceId = namespaceId.dataset(instanceName);
final DatasetCreationSpec instanceSpec = instanceEntry.getValue();
DatasetSpecification existingSpec = AuthorizationUtil.authorizeAs(authorizingUser, new Callable<DatasetSpecification>() {
@Override
public DatasetSpecification call() throws Exception {
return datasetFramework.getDatasetSpec(instanceId);
}
});
if (existingSpec == null) {
LOG.info("Adding dataset instance: {}", instanceName);
AuthorizationUtil.authorizeAs(authorizingUser, new Callable<Void>() {
@Override
public Void call() throws Exception {
datasetFramework.addInstance(instanceSpec.getTypeName(), instanceId, instanceSpec.getProperties(), ownerPrincipal);
return null;
}
});
} else {
if (!existingSpec.getType().equals(instanceSpec.getTypeName())) {
throw new IncompatibleUpdateException(String.format("Existing dataset '%s' of type '%s' may not be updated to type '%s'", instanceName, existingSpec.getType(), instanceSpec.getTypeName()));
}
if (allowDatasetUncheckedUpgrade) {
LOG.info("Updating dataset instance: {}", instanceName);
AuthorizationUtil.authorizeAs(authorizingUser, new Callable<Void>() {
@Override
public Void call() throws Exception {
datasetFramework.updateInstance(instanceId, instanceSpec.getProperties());
return null;
}
});
}
}
}
}
use of io.cdap.cdap.api.dataset.IncompatibleUpdateException in project cdap by caskdata.
the class DatasetDefinitionRegistryWithDefaultModules method testPFSReconfigure.
@Test
public void testPFSReconfigure() throws IncompatibleUpdateException {
DatasetDefinition pfsDef = registry.get(PartitionedFileSet.class.getName());
Assert.assertTrue(pfsDef instanceof Reconfigurable);
DatasetProperties props = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addIntField("i").addStringField("s").build()).build();
DatasetSpecification spec = pfsDef.configure("pfs", props);
DatasetProperties noIprops = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addStringField("s").build()).build();
try {
((Reconfigurable) pfsDef).reconfigure("pfs", noIprops, spec);
Assert.fail("reconfigure should have thrown exception");
} catch (IncompatibleUpdateException e) {
// expected
}
DatasetProperties longIprops = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addLongField("i").addStringField("s").build()).build();
try {
((Reconfigurable) pfsDef).reconfigure("pfs", longIprops, spec);
Assert.fail("reconfigure should have thrown exception");
} catch (IncompatibleUpdateException e) {
// expected
}
DatasetProperties revProps = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addStringField("s").addIntField("i").build()).build();
try {
((Reconfigurable) pfsDef).reconfigure("pfs", revProps, spec);
Assert.fail("reconfigure should have thrown exception");
} catch (IncompatibleUpdateException e) {
// expected
}
// test reconfiguring a PFS created before CDAP-13120, with no defaulted base path
// no base path should be set for the reconfigured dataset either
DatasetProperties oldProps = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addStringField("s").build()).add(PartitionedFileSetDefinition.NAME_AS_BASE_PATH_DEFAULT, "false").build();
DatasetSpecification oldSpec = pfsDef.configure("pfs", oldProps);
DatasetSpecification newSpec = ((Reconfigurable) pfsDef).reconfigure("pfs", oldProps, oldSpec);
// make sure base path is not set
Assert.assertNull(newSpec.getSpecification("files").getProperty(FileSetProperties.BASE_PATH));
// test reconfiguring a PFS created after CDAP-13120, where base path is default to the dataset name
props = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addStringField("s").build()).build();
oldSpec = pfsDef.configure("pfs", props);
newSpec = ((Reconfigurable) pfsDef).reconfigure("pfs", props, oldSpec);
// make sure base path is similarly set, even when not explicitly given
Assert.assertEquals("pfs", newSpec.getSpecification("files").getProperty(FileSetProperties.BASE_PATH));
// make sure it is set for subsequent reconfigures as well
newSpec = ((Reconfigurable) pfsDef).reconfigure("pfs", props, oldSpec);
// make sure base path is similarly set, even when not explicitly given
Assert.assertEquals("pfs", newSpec.getSpecification("files").getProperty(FileSetProperties.BASE_PATH));
}
use of io.cdap.cdap.api.dataset.IncompatibleUpdateException in project cdap by caskdata.
the class DatasetDefinitionRegistryWithDefaultModules method testFileSetReconfigure.
private void testFileSetReconfigure(boolean expectSuccess, DatasetDefinition def, Boolean wasExternal, String path, Boolean newExternal, String newPath, DatasetProperties extraProps) throws IncompatibleUpdateException {
Assert.assertTrue(def instanceof Reconfigurable);
DatasetProperties props = buildFileSetProps(extraProps, wasExternal, path);
DatasetProperties newProps = buildFileSetProps(extraProps, newExternal, newPath);
DatasetSpecification spec = def.configure("fs", props);
if (expectSuccess) {
((Reconfigurable) def).reconfigure("fs", newProps, spec);
} else {
try {
((Reconfigurable) def).reconfigure("fs", newProps, spec);
Assert.fail("reconfigure should have thrown exception");
} catch (IncompatibleUpdateException e) {
// expected
}
}
}
Aggregations