Search in sources :

Example 21 with DatasetMeta

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

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)

Example 22 with DatasetMeta

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

the class RemoteDatasetFramework method getAdmin.

@Nullable
@Override
public <T extends DatasetAdmin> T getAdmin(DatasetId datasetInstanceId, @Nullable ClassLoader parentClassLoader, DatasetClassLoaderProvider classLoaderProvider) throws DatasetManagementException, IOException {
    DatasetMeta instanceInfo = callWithRetries(() -> clientCache.getUnchecked(datasetInstanceId.getParent()).getInstance(datasetInstanceId.getEntityName()));
    if (instanceInfo == null) {
        return null;
    }
    DatasetType type = getType(instanceInfo.getType(), parentClassLoader, classLoaderProvider);
    return (T) type.getAdmin(DatasetContext.from(datasetInstanceId.getNamespace()), instanceInfo.getSpec());
}
Also used : DatasetMeta(io.cdap.cdap.proto.DatasetMeta) Nullable(javax.annotation.Nullable)

Example 23 with DatasetMeta

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

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 24 with DatasetMeta

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

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)

Aggregations

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