Search in sources :

Example 1 with DatasetMeta

use of io.cdap.cdap.proto.DatasetMeta in project cdap by caskdata.

the class DescribeDatasetInstanceCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    DatasetId instance = cliConfig.getCurrentNamespace().dataset(arguments.get(ArgumentName.DATASET.toString()));
    DatasetMeta meta = datasetClient.get(instance);
    Table table = Table.builder().setHeader("hive table", "spec", "type", "principal").setRows(ImmutableList.of(meta), new RowMaker<DatasetMeta>() {

        @Override
        public List<?> makeRow(DatasetMeta object) {
            return Lists.newArrayList(object.getHiveTableName(), GSON.toJson(object.getSpec()), GSON.toJson(object.getType()), object.getOwnerPrincipal());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) DatasetMeta(io.cdap.cdap.proto.DatasetMeta) DatasetId(io.cdap.cdap.proto.id.DatasetId)

Example 2 with DatasetMeta

use of io.cdap.cdap.proto.DatasetMeta in project cdap by caskdata.

the class DatasetInstanceHandlerTest method testUpdateInstance.

@Test
public void testUpdateInstance() throws Exception {
    // nothing has been created, modules and types list is empty
    List<DatasetSpecificationSummary> instances = getInstances().getResponseObject();
    // nothing in the beginning
    Assert.assertEquals(0, instances.size());
    try {
        DatasetProperties props = DatasetProperties.builder().add("prop1", "val1").add(TestModule2.NOT_RECONFIGURABLE, "this").build();
        // deploy modules
        deployModule("module1", TestModule1.class);
        deployModule("module2", TestModule2.class);
        // create dataset instance
        Assert.assertEquals(HttpStatus.SC_OK, createInstance("dataset1", "datasetType2", props).getResponseCode());
        // verify instance was created
        instances = getInstances().getResponseObject();
        Assert.assertEquals(1, instances.size());
        DatasetMeta meta = getInstanceObject("dataset1").getResponseObject();
        Map<String, String> storedOriginalProps = meta.getSpec().getOriginalProperties();
        Assert.assertEquals(props.getProperties(), storedOriginalProps);
        Map<String, String> retrievedProps = getInstanceProperties("dataset1").getResponseObject();
        Assert.assertEquals(props.getProperties(), retrievedProps);
        // these properties are incompatible because TestModule1.NOT_RECONFIGURABLE may not change
        DatasetProperties newProps = DatasetProperties.builder().add("prop2", "val2").add(TestModule2.NOT_RECONFIGURABLE, "that").build();
        Assert.assertEquals(HttpStatus.SC_CONFLICT, updateInstance("dataset1", newProps).getResponseCode());
        // update dataset instance with valid properties
        newProps = DatasetProperties.builder().add("prop2", "val2").add(TestModule2.NOT_RECONFIGURABLE, "this").build();
        Assert.assertEquals(HttpStatus.SC_OK, updateInstance("dataset1", newProps).getResponseCode());
        meta = getInstanceObject("dataset1").getResponseObject();
        Assert.assertEquals(newProps.getProperties(), meta.getSpec().getOriginalProperties());
        Assert.assertEquals("val2", meta.getSpec().getProperty("prop2"));
        Assert.assertNull(meta.getSpec().getProperty("prop1"));
        retrievedProps = getInstanceProperties("dataset1").getResponseObject();
        Assert.assertEquals(newProps.getProperties(), retrievedProps);
    } finally {
        // delete dataset instance
        Assert.assertEquals(HttpStatus.SC_OK, deleteInstance("dataset1").getResponseCode());
        Assert.assertEquals(0, getInstances().getResponseObject().size());
        // delete dataset modules
        Assert.assertEquals(HttpStatus.SC_OK, deleteModule("module2").getResponseCode());
        Assert.assertEquals(HttpStatus.SC_OK, deleteModule("module1").getResponseCode());
    }
}
Also used : DatasetProperties(io.cdap.cdap.api.dataset.DatasetProperties) DatasetMeta(io.cdap.cdap.proto.DatasetMeta) DatasetSpecificationSummary(io.cdap.cdap.proto.DatasetSpecificationSummary) Test(org.junit.Test)

Example 3 with DatasetMeta

use of io.cdap.cdap.proto.DatasetMeta in project cdap by caskdata.

the class DatasetInstanceHandlerTest method testOwner.

@Test
public void testOwner() throws Exception {
    // deploy modules
    deployModule("module1", TestModule1.class);
    // should not be able to create a dataset with invalid kerberos principal format
    HttpResponse response = createInstance(NamespaceId.DEFAULT.dataset("ownedDataset"), "datasetType1", null, DatasetProperties.EMPTY, "alice/bob/somehost.net@somekdc.net");
    Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getResponseCode());
    // should be able to create a dataset with valid kerberos principal format
    String alicePrincipal = "alice/somehost.net@somekdc.net";
    response = createInstance(NamespaceId.DEFAULT.dataset("ownedDataset"), "datasetType1", null, DatasetProperties.EMPTY, alicePrincipal);
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    // owner information should have stored
    Assert.assertEquals(alicePrincipal, ownerAdmin.getOwnerPrincipal(NamespaceId.DEFAULT.dataset("ownedDataset")));
    // should be able to retrieve owner information back
    DatasetMeta meta = getInstanceObject("ownedDataset").getResponseObject();
    Assert.assertEquals(alicePrincipal, meta.getOwnerPrincipal());
    // deleting the dataset should delete the owner information
    response = deleteInstance(NamespaceId.DEFAULT.dataset("ownedDataset"));
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    Assert.assertNull(ownerAdmin.getOwner(NamespaceId.DEFAULT.dataset("ownedDataset")));
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) DatasetMeta(io.cdap.cdap.proto.DatasetMeta) Test(org.junit.Test)

Example 4 with DatasetMeta

use of io.cdap.cdap.proto.DatasetMeta in project cdap by caskdata.

the class RemoteDatasetFramework method getDataset.

@Nullable
@Override
public <T extends Dataset> T getDataset(DatasetId id, Map<String, String> arguments, @Nullable ClassLoader classLoader, DatasetClassLoaderProvider classLoaderProvider, @Nullable Iterable<? extends EntityId> owners, AccessType accessType) throws DatasetManagementException, IOException {
    DatasetMeta datasetMeta = callWithRetries(() -> clientCache.getUnchecked(id.getParent()).getInstance(id.getEntityName()));
    if (datasetMeta == null) {
        return null;
    }
    DatasetType type = getType(datasetMeta.getType(), classLoader, classLoaderProvider);
    return (T) type.getDataset(DatasetContext.from(id.getNamespace()), datasetMeta.getSpec(), arguments);
}
Also used : DatasetMeta(io.cdap.cdap.proto.DatasetMeta) Nullable(javax.annotation.Nullable)

Example 5 with DatasetMeta

use of io.cdap.cdap.proto.DatasetMeta in project cdap by caskdata.

the class DatasetInstanceService method get.

/**
 * Gets the metadata for a dataset instance.
 *
 * @param instance instance to get
 * @return the dataset instance's {@link DatasetMeta}
 * @throws NotFoundException if either the namespace or dataset instance is not found,
 * @throws IOException if there is a problem in making an HTTP request to check if the namespace exists
 * @throws UnauthorizedException if perimeter security and authorization are enabled, and the current user does not
 *  have any privileges on the #instance
 */
DatasetMeta get(final DatasetId instance) throws Exception {
    // ensure user has correct privileges before getting the meta if the dataset is not a system dataset
    if (!DatasetsUtil.isSystemDatasetInUserNamespace(instance)) {
        LOG.trace("Authorizing GET for dataset {}", instance.getDataset());
        accessEnforcer.enforce(instance, authenticationContext.getPrincipal(), StandardPermission.GET);
        LOG.trace("Authorized GET for dataset {}", instance.getDataset());
    }
    // Application Deployment first makes a call to the dataset service to check if the instance already exists with
    // a different type. To make sure that that call responds with the right exceptions if necessary, first fetch the
    // meta from the cache and throw appropriate exceptions if necessary.
    DatasetMeta datasetMeta;
    try {
        LOG.trace("Retrieving instance metadata from cache for dataset {}", instance.getDataset());
        datasetMeta = metaCache.get(instance);
        LOG.trace("Retrieved instance metadata from cache for dataset {}", instance.getDataset());
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        if ((cause instanceof Exception) && (cause instanceof HttpErrorStatusProvider)) {
            throw (Exception) cause;
        }
        throw e;
    }
    return datasetMeta;
}
Also used : DatasetMeta(io.cdap.cdap.proto.DatasetMeta) HttpErrorStatusProvider(io.cdap.cdap.api.common.HttpErrorStatusProvider) ExecutionException(java.util.concurrent.ExecutionException) HandlerException(io.cdap.cdap.common.HandlerException) NotFoundException(io.cdap.cdap.common.NotFoundException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) DatasetTypeNotFoundException(io.cdap.cdap.common.DatasetTypeNotFoundException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) IOException(java.io.IOException) DatasetAlreadyExistsException(io.cdap.cdap.common.DatasetAlreadyExistsException) ExecutionException(java.util.concurrent.ExecutionException) DatasetNotFoundException(io.cdap.cdap.common.DatasetNotFoundException)

Aggregations

DatasetMeta (io.cdap.cdap.proto.DatasetMeta)12 Test (org.junit.Test)5 DatasetTypeNotFoundException (io.cdap.cdap.common.DatasetTypeNotFoundException)4 NotFoundException (io.cdap.cdap.common.NotFoundException)4 DatasetNotFoundException (io.cdap.cdap.common.DatasetNotFoundException)3 DatasetSpecificationSummary (io.cdap.cdap.proto.DatasetSpecificationSummary)3 HttpResponse (io.cdap.common.http.HttpResponse)3 DatasetProperties (io.cdap.cdap.api.dataset.DatasetProperties)2 DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)2 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)2 DatasetInstanceConfiguration (io.cdap.cdap.proto.DatasetInstanceConfiguration)2 DatasetModuleMeta (io.cdap.cdap.proto.DatasetModuleMeta)2 DatasetTypeMeta (io.cdap.cdap.proto.DatasetTypeMeta)2 DatasetId (io.cdap.cdap.proto.id.DatasetId)2 DatasetTypeId (io.cdap.cdap.proto.id.DatasetTypeId)2 HashMap (java.util.HashMap)2 Nullable (javax.annotation.Nullable)2 HttpErrorStatusProvider (io.cdap.cdap.api.common.HttpErrorStatusProvider)1 RowMaker (io.cdap.cdap.cli.util.RowMaker)1 Table (io.cdap.cdap.cli.util.table.Table)1