Search in sources :

Example 1 with DatasetMeta

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;
}
Also used : DatasetMeta(co.cask.cdap.proto.DatasetMeta) HttpErrorStatusProvider(co.cask.cdap.api.common.HttpErrorStatusProvider) ExecutionException(java.util.concurrent.ExecutionException) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) DatasetNotFoundException(co.cask.cdap.common.DatasetNotFoundException) DatasetTypeNotFoundException(co.cask.cdap.common.DatasetTypeNotFoundException) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) HandlerException(co.cask.cdap.common.HandlerException) DatasetAlreadyExistsException(co.cask.cdap.common.DatasetAlreadyExistsException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NotFoundException(co.cask.cdap.common.NotFoundException)

Example 2 with 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);
}
Also used : DatasetTypeId(co.cask.cdap.proto.id.DatasetTypeId) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) DatasetNotFoundException(co.cask.cdap.common.DatasetNotFoundException) DatasetTypeNotFoundException(co.cask.cdap.common.DatasetTypeNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) DatasetMeta(co.cask.cdap.proto.DatasetMeta)

Example 3 with DatasetMeta

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);
}
Also used : DatasetMeta(co.cask.cdap.proto.DatasetMeta) Nullable(javax.annotation.Nullable)

Example 4 with DatasetMeta

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);
}
Also used : DatasetMeta(co.cask.cdap.proto.DatasetMeta)

Example 5 with DatasetMeta

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());
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) HashMap(java.util.HashMap) DatasetMeta(co.cask.cdap.proto.DatasetMeta) NotFoundException(co.cask.cdap.common.NotFoundException) DatasetInstanceConfiguration(co.cask.cdap.proto.DatasetInstanceConfiguration) ProgramId(co.cask.cdap.proto.id.ProgramId) Test(org.junit.Test)

Aggregations

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