use of co.cask.cdap.proto.DatasetMeta in project cdap by caskdata.
the class DatasetInstanceService method get.
/**
* Gets a dataset instance.
*
* @param instance instance to get
* @param owners the {@link EntityId entities} that will be using the dataset instance
* @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, List<? extends EntityId> owners) throws Exception {
// 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 {
datasetMeta = metaCache.get(instance);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if ((cause instanceof Exception) && (cause instanceof HttpErrorStatusProvider)) {
throw (Exception) cause;
}
throw e;
}
// Only return the above datasetMeta if authorization succeeds
ensureAccess(instance);
return datasetMeta;
}
use of co.cask.cdap.proto.DatasetMeta in project cdap by caskdata.
the class DatasetInstanceService method getFromMds.
/**
* Read the dataset meta data (instance and type) from MDS.
*/
private DatasetMeta getFromMds(DatasetId instance) throws Exception {
// TODO: CDAP-3901 add back namespace existence check
DatasetSpecification spec = instanceManager.get(instance);
if (spec == null) {
throw new NotFoundException(instance);
}
spec = DatasetsUtil.fixOriginalProperties(spec);
DatasetTypeId datasetTypeId = instance.getParent().datasetType(spec.getType());
DatasetTypeMeta typeMeta = getTypeInfo(instance.getParent(), spec.getType());
if (typeMeta == null) {
// TODO: This shouldn't happen unless CDAP is in an invalid state - maybe give different error
throw new NotFoundException(datasetTypeId);
}
// for system dataset do not look up owner information in store as we know that it will be null.
// Also, this is required for CDAP to start, because initially we don't want to look up owner admin
// (causing its own lookup) as the SystemDatasetInitiator.getDataset is called when CDAP starts
String ownerPrincipal = null;
if (!NamespaceId.SYSTEM.equals(instance.getNamespaceId())) {
ownerPrincipal = ownerAdmin.getOwnerPrincipal(instance);
}
return new DatasetMeta(spec, typeMeta, null, ownerPrincipal);
}
use of co.cask.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 = clientCache.getUnchecked(id.getParent()).getInstance(id.getEntityName(), owners);
if (datasetMeta == null) {
return null;
}
DatasetType type = getType(datasetMeta.getType(), classLoader, classLoaderProvider);
return (T) type.getDataset(DatasetContext.from(id.getNamespace()), datasetMeta.getSpec(), arguments);
}
use of co.cask.cdap.proto.DatasetMeta in project cdap by caskdata.
the class DatasetClient method updateExisting.
/**
* Updates the existing properties of a dataset.
*
* @param instance the dataset to update
* @param properties properties to set
* @throws NotFoundException if the dataset is not found
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public void updateExisting(DatasetId instance, Map<String, String> properties) throws NotFoundException, IOException, UnauthenticatedException, ConflictException, UnauthorizedException {
DatasetMeta meta = get(instance);
Map<String, String> existingProperties = meta.getSpec().getProperties();
Map<String, String> resolvedProperties = Maps.newHashMap();
resolvedProperties.putAll(existingProperties);
resolvedProperties.putAll(properties);
update(instance, resolvedProperties);
}
use of co.cask.cdap.proto.DatasetMeta in project cdap by caskdata.
the class DatasetInstanceServiceTest method testInstanceMetaCache.
@Test
public void testInstanceMetaCache() throws Exception {
// deploy a dataset
instanceService.create(NamespaceId.DEFAULT.getEntityName(), "testds", new DatasetInstanceConfiguration("table", new HashMap<String, String>()));
// get the dataset meta for two different owners, assert it is the same
DatasetMeta meta = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app1", ProgramType.FLOW, "flow1")));
DatasetMeta met2 = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app2", ProgramType.FLOW, "flow2")));
Assert.assertSame(meta, met2);
// update the dataset
instanceService.update(NamespaceId.DEFAULT.dataset("testds"), ImmutableMap.of("ttl", "12345678"));
// get the dataset meta, validate it changed
met2 = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app2", ProgramType.FLOW, "flow2")));
Assert.assertNotSame(meta, met2);
Assert.assertEquals("12345678", met2.getSpec().getProperty("ttl"));
// delete the dataset
instanceService.drop(NamespaceId.DEFAULT.dataset("testds"));
// get the dataset meta, validate not found
try {
instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app1", ProgramType.FLOW, "flow2")));
Assert.fail("get() should have thrown NotFoundException");
} catch (NotFoundException e) {
// expected
}
// recreate the dataset
instanceService.create(NamespaceId.DEFAULT.getNamespace(), "testds", new DatasetInstanceConfiguration("table", new HashMap<String, String>()));
// get the dataset meta, validate it is up to date
met2 = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app2", ProgramType.FLOW, "flow2")));
Assert.assertEquals(meta.getSpec(), met2.getSpec());
}
Aggregations