Search in sources :

Example 11 with IncompatibleUpdateException

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
    }
}
Also used : DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetContext(io.cdap.cdap.api.dataset.DatasetContext) Map(java.util.Map) IncompatibleUpdateException(io.cdap.cdap.api.dataset.IncompatibleUpdateException) Test(org.junit.Test)

Example 12 with IncompatibleUpdateException

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());
    }
}
Also used : ConflictException(io.cdap.cdap.common.ConflictException) DatasetProperties(io.cdap.cdap.api.dataset.DatasetProperties) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) DatasetId(io.cdap.cdap.proto.id.DatasetId) IncompatibleUpdateException(io.cdap.cdap.api.dataset.IncompatibleUpdateException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 13 with IncompatibleUpdateException

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;
                    }
                });
            }
        }
    }
}
Also used : DatasetCreationSpec(io.cdap.cdap.internal.dataset.DatasetCreationSpec) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) Map(java.util.Map) IncompatibleUpdateException(io.cdap.cdap.api.dataset.IncompatibleUpdateException) DatasetId(io.cdap.cdap.proto.id.DatasetId) IncompatibleUpdateException(io.cdap.cdap.api.dataset.IncompatibleUpdateException)

Example 14 with IncompatibleUpdateException

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));
}
Also used : DatasetProperties(io.cdap.cdap.api.dataset.DatasetProperties) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetDefinition(io.cdap.cdap.api.dataset.DatasetDefinition) Reconfigurable(io.cdap.cdap.api.dataset.Reconfigurable) IncompatibleUpdateException(io.cdap.cdap.api.dataset.IncompatibleUpdateException) Test(org.junit.Test)

Example 15 with IncompatibleUpdateException

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
        }
    }
}
Also used : DatasetProperties(io.cdap.cdap.api.dataset.DatasetProperties) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) Reconfigurable(io.cdap.cdap.api.dataset.Reconfigurable) IncompatibleUpdateException(io.cdap.cdap.api.dataset.IncompatibleUpdateException)

Aggregations

DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)22 IncompatibleUpdateException (io.cdap.cdap.api.dataset.IncompatibleUpdateException)22 DatasetProperties (io.cdap.cdap.api.dataset.DatasetProperties)12 Reconfigurable (io.cdap.cdap.api.dataset.Reconfigurable)8 DatasetAdmin (io.cdap.cdap.api.dataset.DatasetAdmin)6 DatasetDefinition (io.cdap.cdap.api.dataset.DatasetDefinition)6 Updatable (io.cdap.cdap.api.dataset.Updatable)6 Test (org.junit.Test)6 DatasetContext (io.cdap.cdap.api.dataset.DatasetContext)4 ConflictException (io.cdap.cdap.common.ConflictException)4 DatasetType (io.cdap.cdap.data2.datafabric.dataset.DatasetType)4 DatasetId (io.cdap.cdap.proto.id.DatasetId)4 Map (java.util.Map)4 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)2 InstanceConflictException (io.cdap.cdap.api.dataset.InstanceConflictException)2 InstanceNotFoundException (io.cdap.cdap.api.dataset.InstanceNotFoundException)2 AbstractDatasetDefinition (io.cdap.cdap.api.dataset.lib.AbstractDatasetDefinition)2 Partitioning (io.cdap.cdap.api.dataset.lib.Partitioning)2 AccessException (io.cdap.cdap.api.security.AccessException)2 BadRequestException (io.cdap.cdap.common.BadRequestException)2