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;
}
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());
}
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());
}
}
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")));
}
Aggregations