Search in sources :

Example 1 with IncompatibleUpdateException

use of co.cask.cdap.api.dataset.IncompatibleUpdateException in project cdap by caskdata.

the class DatasetAdminOpHTTPHandler method update.

@POST
@Path("/data/datasets/{name}/admin/update")
public void update(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String name) {
    propagateUserId(request);
    InternalDatasetUpdateParams params = GSON.fromJson(request.getContent().toString(Charsets.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);
        DatasetSpecification spec = datasetAdminService.createOrUpdate(instanceId, typeMeta, props, existing);
        responder.sendJson(HttpResponseStatus.OK, spec);
    } catch (NotFoundException e) {
        LOG.debug("Got handler exception", e);
        responder.sendString(HttpResponseStatus.NOT_FOUND, StringUtils.defaultIfEmpty(e.getMessage(), ""));
    } catch (BadRequestException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (IncompatibleUpdateException e) {
        responder.sendString(HttpResponseStatus.CONFLICT, e.getMessage());
    } catch (Exception e) {
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : DatasetProperties(co.cask.cdap.api.dataset.DatasetProperties) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) NotFoundException(co.cask.cdap.common.NotFoundException) BadRequestException(co.cask.cdap.common.BadRequestException) IncompatibleUpdateException(co.cask.cdap.api.dataset.IncompatibleUpdateException) NotFoundException(co.cask.cdap.common.NotFoundException) BadRequestException(co.cask.cdap.common.BadRequestException) DatasetId(co.cask.cdap.proto.id.DatasetId) IncompatibleUpdateException(co.cask.cdap.api.dataset.IncompatibleUpdateException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with IncompatibleUpdateException

use of co.cask.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.
   */
void createInstances(NamespaceId namespaceId, Map<String, DatasetCreationSpec> datasets, @Nullable KerberosPrincipalId ownerPrincipal) throws Exception {
    // create dataset instances
    for (Map.Entry<String, DatasetCreationSpec> instanceEntry : datasets.entrySet()) {
        String instanceName = instanceEntry.getKey();
        DatasetId instanceId = namespaceId.dataset(instanceName);
        DatasetCreationSpec instanceSpec = instanceEntry.getValue();
        DatasetSpecification existingSpec = datasetFramework.getDatasetSpec(instanceId);
        if (existingSpec == null) {
            LOG.info("Adding dataset instance: {}", instanceName);
            datasetFramework.addInstance(instanceSpec.getTypeName(), instanceId, instanceSpec.getProperties(), ownerPrincipal);
        } 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);
                datasetFramework.updateInstance(instanceId, instanceSpec.getProperties());
            }
        }
    }
}
Also used : DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) Map(java.util.Map) DatasetId(co.cask.cdap.proto.id.DatasetId) IncompatibleUpdateException(co.cask.cdap.api.dataset.IncompatibleUpdateException)

Example 3 with IncompatibleUpdateException

use of co.cask.cdap.api.dataset.IncompatibleUpdateException in project cdap by caskdata.

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) throws IOException {
            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(co.cask.cdap.api.dataset.DatasetSpecification) DatasetContext(co.cask.cdap.api.dataset.DatasetContext) Map(java.util.Map) IncompatibleUpdateException(co.cask.cdap.api.dataset.IncompatibleUpdateException) Test(org.junit.Test)

Example 4 with IncompatibleUpdateException

use of co.cask.cdap.api.dataset.IncompatibleUpdateException in project cdap by caskdata.

the class InMemoryDatasetFramework method updateInstance.

@Override
public void updateInstance(DatasetId datasetInstanceId, DatasetProperties props) throws DatasetManagementException, IOException {
    writeLock.lock();
    try {
        DatasetSpecification oldSpec = instances.get(datasetInstanceId.getParent(), datasetInstanceId);
        if (oldSpec == null) {
            throw new InstanceNotFoundException(datasetInstanceId.getEntityName());
        }
        DatasetDefinition def = getDefinitionForType(datasetInstanceId.getParent(), oldSpec.getType());
        if (def == null) {
            throw new DatasetManagementException(String.format("Dataset type '%s' is neither registered in the '%s' namespace nor in the system namespace", oldSpec.getType(), datasetInstanceId.getParent()));
        }
        DatasetSpecification spec = AbstractDatasetDefinition.reconfigure(def, datasetInstanceId.getEntityName(), props, oldSpec).setOriginalProperties(props);
        if (props.getDescription() != null) {
            spec = spec.setDescription(props.getDescription());
        }
        instances.put(datasetInstanceId.getParent(), datasetInstanceId, spec);
        DatasetAdmin admin = def.getAdmin(DatasetContext.from(datasetInstanceId.getNamespace()), spec, null);
        if (admin instanceof Updatable) {
            ((Updatable) admin).update(oldSpec);
        } else {
            admin.upgrade();
        }
        publishAudit(datasetInstanceId, AuditType.UPDATE);
    } catch (IncompatibleUpdateException e) {
        throw new InstanceConflictException("Update failed for dataset instance " + datasetInstanceId, e);
    } finally {
        writeLock.unlock();
    }
}
Also used : DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) InstanceConflictException(co.cask.cdap.api.dataset.InstanceConflictException) InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) Updatable(co.cask.cdap.api.dataset.Updatable) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetAdmin(co.cask.cdap.api.dataset.DatasetAdmin) AbstractDatasetDefinition(co.cask.cdap.api.dataset.lib.AbstractDatasetDefinition) DatasetDefinition(co.cask.cdap.api.dataset.DatasetDefinition) IncompatibleUpdateException(co.cask.cdap.api.dataset.IncompatibleUpdateException)

Example 5 with IncompatibleUpdateException

use of co.cask.cdap.api.dataset.IncompatibleUpdateException in project cdap by caskdata.

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) {
    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);
        DatasetSpecification spec = datasetAdminService.createOrUpdate(instanceId, typeMeta, props, existing);
        responder.sendJson(HttpResponseStatus.OK, GSON.toJson(spec));
    } catch (NotFoundException e) {
        LOG.debug("Got handler exception", e);
        responder.sendString(HttpResponseStatus.NOT_FOUND, StringUtils.defaultIfEmpty(e.getMessage(), ""));
    } catch (BadRequestException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (IncompatibleUpdateException e) {
        responder.sendString(HttpResponseStatus.CONFLICT, e.getMessage());
    } catch (Exception e) {
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : DatasetProperties(co.cask.cdap.api.dataset.DatasetProperties) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) NotFoundException(co.cask.cdap.common.NotFoundException) BadRequestException(co.cask.cdap.common.BadRequestException) IncompatibleUpdateException(co.cask.cdap.api.dataset.IncompatibleUpdateException) NotFoundException(co.cask.cdap.common.NotFoundException) BadRequestException(co.cask.cdap.common.BadRequestException) DatasetId(co.cask.cdap.proto.id.DatasetId) IncompatibleUpdateException(co.cask.cdap.api.dataset.IncompatibleUpdateException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)13 IncompatibleUpdateException (co.cask.cdap.api.dataset.IncompatibleUpdateException)13 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)7 Reconfigurable (co.cask.cdap.api.dataset.Reconfigurable)4 DatasetId (co.cask.cdap.proto.id.DatasetId)4 DatasetAdmin (co.cask.cdap.api.dataset.DatasetAdmin)3 DatasetDefinition (co.cask.cdap.api.dataset.DatasetDefinition)3 Updatable (co.cask.cdap.api.dataset.Updatable)3 BadRequestException (co.cask.cdap.common.BadRequestException)3 NotFoundException (co.cask.cdap.common.NotFoundException)3 Map (java.util.Map)3 Test (org.junit.Test)3 DatasetContext (co.cask.cdap.api.dataset.DatasetContext)2 DatasetType (co.cask.cdap.data2.datafabric.dataset.DatasetType)2 DatasetCreationSpec (co.cask.cdap.internal.dataset.DatasetCreationSpec)2 DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)1 InstanceConflictException (co.cask.cdap.api.dataset.InstanceConflictException)1