Search in sources :

Example 36 with DatasetSpecification

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

the class HiveExploreStructuredRecordTestRun method testMissingSchemaFails.

@Test(expected = IllegalArgumentException.class)
public void testMissingSchemaFails() throws Exception {
    DatasetId instanceId = NAMESPACE_ID.dataset("badtable");
    datasetFramework.addInstance("TableWrapper", instanceId, DatasetProperties.EMPTY);
    DatasetSpecification spec = datasetFramework.getDatasetSpec(instanceId);
    try {
        exploreTableManager.enableDataset(instanceId, spec, false);
    } finally {
        datasetFramework.deleteInstance(instanceId);
    }
}
Also used : DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 37 with DatasetSpecification

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

the class FakeDatasetDefinition method getDataset.

@Override
public FakeDataset getDataset(DatasetContext datasetContext, DatasetSpecification spec, Map<String, String> arguments, ClassLoader classLoader) throws IOException {
    DatasetSpecification kvTableSpec = spec.getSpecification("objects");
    KeyValueTable table = tableDef.getDataset(datasetContext, kvTableSpec, arguments, classLoader);
    return new FakeDataset(spec.getName(), table);
}
Also used : KeyValueTable(co.cask.cdap.api.dataset.lib.KeyValueTable) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification)

Example 38 with DatasetSpecification

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

the class StandaloneDatasetDefinition method getDataset.

@Override
public StandaloneDataset getDataset(DatasetContext datasetContext, DatasetSpecification spec, Map<String, String> arguments, ClassLoader classLoader) throws IOException {
    DatasetSpecification kvTableSpec = spec.getSpecification("objects");
    KeyValueTable table = tableDef.getDataset(datasetContext, kvTableSpec, arguments, classLoader);
    return new StandaloneDataset(spec.getName(), table);
}
Also used : KeyValueTable(co.cask.cdap.api.dataset.lib.KeyValueTable) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification)

Example 39 with DatasetSpecification

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

the class ExploreExecutorHttpHandler method updateDataset.

/**
   * Enable ad-hoc exploration of a dataset instance.
   */
@POST
@Path("datasets/{dataset}/update")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void updateDataset(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dataset") String datasetName) throws BadRequestException {
    final DatasetId datasetId = new DatasetId(namespace, datasetName);
    try {
        UpdateExploreParameters params = readUpdateParameters(request);
        final DatasetSpecification oldSpec = params.getOldSpec();
        final DatasetSpecification datasetSpec = params.getNewSpec();
        QueryHandle handle;
        if (oldSpec.equals(datasetSpec)) {
            handle = QueryHandle.NO_OP;
        } else {
            handle = impersonator.doAs(datasetId, new Callable<QueryHandle>() {

                @Override
                public QueryHandle call() throws Exception {
                    return exploreTableManager.updateDataset(datasetId, datasetSpec, oldSpec);
                }
            });
        }
        JsonObject json = new JsonObject();
        json.addProperty("handle", handle.getHandle());
        responder.sendJson(HttpResponseStatus.OK, json);
    } catch (IllegalArgumentException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (ExploreException e) {
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error updating explore on dataset " + datasetId);
    } catch (SQLException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, "SQL exception while trying to update explore on dataset " + datasetId);
    } catch (UnsupportedTypeException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, "Schema for dataset " + datasetId + " is not supported for exploration: " + e.getMessage());
    } catch (Throwable e) {
        LOG.error("Got exception:", e);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : UpdateExploreParameters(co.cask.cdap.explore.client.UpdateExploreParameters) SQLException(java.sql.SQLException) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) JsonObject(com.google.gson.JsonObject) UnsupportedTypeException(co.cask.cdap.api.data.schema.UnsupportedTypeException) QueryHandle(co.cask.cdap.proto.QueryHandle) Callable(java.util.concurrent.Callable) DatasetId(co.cask.cdap.proto.id.DatasetId) ExploreException(co.cask.cdap.explore.service.ExploreException) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) POST(javax.ws.rs.POST)

Example 40 with DatasetSpecification

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

the class DatasetAdminOpHTTPHandler method drop.

@POST
@Path("/data/datasets/{name}/admin/drop")
public void drop(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String instanceName) throws Exception {
    propagateUserId(request);
    InternalDatasetDropParams params = GSON.fromJson(request.getContent().toString(Charsets.UTF_8), InternalDatasetDropParams.class);
    Preconditions.checkArgument(params.getInstanceSpec() != null, "Missing required 'instanceSpec' parameter.");
    Preconditions.checkArgument(params.getTypeMeta() != null, "Missing required 'typeMeta' parameter.");
    DatasetSpecification spec = params.getInstanceSpec();
    DatasetTypeMeta typeMeta = params.getTypeMeta();
    try {
        datasetAdminService.drop(new DatasetId(namespaceId, instanceName), typeMeta, spec);
        responder.sendJson(HttpResponseStatus.OK, spec);
    } catch (BadRequestException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    }
}
Also used : DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) BadRequestException(co.cask.cdap.common.BadRequestException) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)72 DatasetId (co.cask.cdap.proto.id.DatasetId)21 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)17 IncompatibleUpdateException (co.cask.cdap.api.dataset.IncompatibleUpdateException)15 Test (org.junit.Test)14 DatasetDefinition (co.cask.cdap.api.dataset.DatasetDefinition)11 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)10 POST (javax.ws.rs.POST)10 Path (javax.ws.rs.Path)10 DatasetAdmin (co.cask.cdap.api.dataset.DatasetAdmin)9 DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)9 NotFoundException (co.cask.cdap.common.NotFoundException)8 AbstractDatasetDefinition (co.cask.cdap.api.dataset.lib.AbstractDatasetDefinition)7 BadRequestException (co.cask.cdap.common.BadRequestException)7 IOException (java.io.IOException)7 DatasetSpecificationSummary (co.cask.cdap.proto.DatasetSpecificationSummary)6 Map (java.util.Map)6 DatasetNotFoundException (co.cask.cdap.common.DatasetNotFoundException)5 Reconfigurable (co.cask.cdap.api.dataset.Reconfigurable)4 Updatable (co.cask.cdap.api.dataset.Updatable)4