Search in sources :

Example 16 with DatasetModuleMeta

use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.

the class DatasetTypeService method delete.

/**
   * Deletes the specified {@link DatasetModuleId}
   */
void delete(DatasetModuleId datasetModuleId) throws Exception {
    NamespaceId namespaceId = datasetModuleId.getParent();
    if (NamespaceId.SYSTEM.equals(namespaceId)) {
        throw new UnauthorizedException(String.format("Cannot delete module '%s' from '%s' namespace.", datasetModuleId.getModule(), datasetModuleId.getNamespace()));
    }
    ensureNamespaceExists(namespaceId);
    DatasetModuleMeta moduleMeta = typeManager.getModule(datasetModuleId);
    if (moduleMeta == null) {
        throw new DatasetModuleNotFoundException(datasetModuleId);
    }
    Principal principal = authenticationContext.getPrincipal();
    authorizationEnforcer.enforce(datasetModuleId, principal, Action.ADMIN);
    try {
        typeManager.deleteModule(datasetModuleId);
    } catch (DatasetModuleConflictException e) {
        throw new DatasetModuleCannotBeDeletedException(datasetModuleId, e.getMessage());
    }
    // revoke all privileges on the module to be deleted
    revokeAllPrivilegesOnModule(datasetModuleId, moduleMeta);
}
Also used : DatasetModuleNotFoundException(co.cask.cdap.common.DatasetModuleNotFoundException) DatasetModuleConflictException(co.cask.cdap.data2.datafabric.dataset.type.DatasetModuleConflictException) DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) NamespaceId(co.cask.cdap.proto.id.NamespaceId) DatasetModuleCannotBeDeletedException(co.cask.cdap.common.DatasetModuleCannotBeDeletedException) Principal(co.cask.cdap.proto.security.Principal)

Example 17 with DatasetModuleMeta

use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.

the class DatasetTypeService method deleteSystemModules.

private void deleteSystemModules() throws Exception {
    final List<DatasetModuleMeta> toRevoke = new ArrayList<>();
    Transactions.createTransactional(datasetCache).execute(60, new TxRunnable() {

        @Override
        public void run(DatasetContext context) throws Exception {
            DatasetTypeMDS datasetTypeMDS = datasetCache.getDataset(DatasetMetaTableUtil.META_TABLE_NAME);
            Collection<DatasetModuleMeta> allDatasets = datasetTypeMDS.getModules(NamespaceId.SYSTEM);
            for (DatasetModuleMeta ds : allDatasets) {
                if (ds.getJarLocationPath() == null) {
                    LOG.debug("Deleting system dataset module: {}", ds.toString());
                    DatasetModuleId moduleId = NamespaceId.SYSTEM.datasetModule(ds.getName());
                    datasetTypeMDS.deleteModule(moduleId);
                    toRevoke.add(ds);
                }
            }
        }
    });
    long startTime = System.currentTimeMillis();
    LOG.trace("Revoking all privileges for {} system dataset modules. ", toRevoke.size());
    for (DatasetModuleMeta ds : toRevoke) {
        revokeAllPrivilegesOnModule(NamespaceId.SYSTEM.datasetModule(ds.getName()), ds);
    }
    long doneTime = System.currentTimeMillis();
    float elapsedSeconds = doneTime == startTime ? 0.0F : ((float) doneTime - startTime) / 1000;
    LOG.debug("Revoking all privileges for {} system dataset modules took {} seconds.", toRevoke.size(), elapsedSeconds);
}
Also used : DatasetTypeMDS(co.cask.cdap.data2.datafabric.dataset.service.mds.DatasetTypeMDS) DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) TxRunnable(co.cask.cdap.api.TxRunnable) ArrayList(java.util.ArrayList) Collection(java.util.Collection) DatasetContext(co.cask.cdap.api.data.DatasetContext) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) ConflictException(co.cask.cdap.common.ConflictException) DatasetModuleConflictException(co.cask.cdap.data2.datafabric.dataset.type.DatasetModuleConflictException) DatasetTypeNotFoundException(co.cask.cdap.common.DatasetTypeNotFoundException) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) DatasetModuleNotFoundException(co.cask.cdap.common.DatasetModuleNotFoundException) IOException(java.io.IOException) DatasetModuleCannotBeDeletedException(co.cask.cdap.common.DatasetModuleCannotBeDeletedException) NotFoundException(co.cask.cdap.common.NotFoundException)

Example 18 with DatasetModuleMeta

use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.

the class DatasetTypeMDS method writeModule.

public void writeModule(NamespaceId namespaceId, DatasetModuleMeta moduleMeta) {
    DatasetModuleId datasetModuleId = namespaceId.datasetModule(moduleMeta.getName());
    DatasetModuleMeta existing = getModule(datasetModuleId);
    write(getModuleKey(namespaceId.getEntityName(), moduleMeta.getName()), moduleMeta);
    for (String type : moduleMeta.getTypes()) {
        writeTypeToModuleMapping(namespaceId.datasetType(type), datasetModuleId);
    }
    if (existing != null) {
        Set<String> removed = new HashSet<>(existing.getTypes());
        removed.removeAll(moduleMeta.getTypes());
        for (String type : removed) {
            deleteAll(getTypeKey(datasetModuleId.getNamespace(), type));
        }
    }
}
Also used : DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) HashSet(java.util.HashSet)

Example 19 with DatasetModuleMeta

use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.

the class DatasetTypeHandlerTest method verifyAll.

private void verifyAll(Set<DatasetModuleMeta> expectedModules, Map<String, List<String>> typeDependencies) throws IOException {
    Set<DatasetModuleMeta> actualModules = new HashSet<>(getModules().getResponseObject());
    Assert.assertEquals(expectedModules, actualModules);
    for (DatasetModuleMeta expectedModule : expectedModules) {
        ObjectResponse<DatasetModuleMeta> response = getModule(expectedModule.getName());
        Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
        Assert.assertEquals(expectedModule, response.getResponseObject());
        for (String type : expectedModule.getTypes()) {
            ObjectResponse<DatasetTypeMeta> typeResponse = getType(type);
            Assert.assertEquals(HttpStatus.SC_OK, typeResponse.getResponseCode());
            verify(typeResponse.getResponseObject(), type, typeDependencies.get(type));
        }
    }
    List<DatasetTypeMeta> actualTypes = getTypes().getResponseObject();
    Assert.assertEquals(actualTypes.size(), typeDependencies.size());
    Assert.assertTrue(Iterables.elementsEqual(typeDependencies.keySet(), Iterables.transform(actualTypes, new Function<DatasetTypeMeta, String>() {

        @Nullable
        @Override
        public String apply(@Nullable DatasetTypeMeta input) {
            return input == null ? null : input.getName();
        }
    })));
    for (DatasetTypeMeta typeMeta : actualTypes) {
        verify(typeMeta, typeMeta.getName(), typeDependencies.get(typeMeta.getName()));
    }
}
Also used : DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) Nullable(javax.annotation.Nullable) HashSet(java.util.HashSet)

Example 20 with DatasetModuleMeta

use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.

the class DatasetModuleClient method get.

/**
   * Gets information about a dataset module.
   *
   * @param module the dataset module
   * @return {@link DatasetModuleMeta} of the dataset module
   * @throws DatasetModuleNotFoundException if the dataset module with the specified name was not found
   * @throws IOException if a network error occurred
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public DatasetModuleMeta get(DatasetModuleId module) throws DatasetModuleNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(module.getParent(), String.format("data/modules/%s", module.getModule()));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new DatasetModuleNotFoundException(module);
    }
    return ObjectResponse.fromJsonBody(response, DatasetModuleMeta.class).getResponseObject();
}
Also used : DatasetModuleNotFoundException(co.cask.cdap.common.DatasetModuleNotFoundException) DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) HttpResponse(co.cask.common.http.HttpResponse) URL(java.net.URL)

Aggregations

DatasetModuleMeta (co.cask.cdap.proto.DatasetModuleMeta)21 DatasetModuleId (co.cask.cdap.proto.id.DatasetModuleId)6 DatasetModuleNotFoundException (co.cask.cdap.common.DatasetModuleNotFoundException)5 DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)5 DatasetTypeMDS (co.cask.cdap.data2.datafabric.dataset.service.mds.DatasetTypeMDS)4 Principal (co.cask.cdap.proto.security.Principal)4 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)4 IOException (java.io.IOException)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 RowMaker (co.cask.cdap.cli.util.RowMaker)3 Table (co.cask.cdap.cli.util.table.Table)3 DatasetInstanceMDS (co.cask.cdap.data2.datafabric.dataset.service.mds.DatasetInstanceMDS)3 DatasetModuleConflictException (co.cask.cdap.data2.datafabric.dataset.type.DatasetModuleConflictException)3 TypeConflictException (co.cask.cdap.data2.dataset2.TypeConflictException)3 File (java.io.File)3 Location (org.apache.twill.filesystem.Location)3 Test (org.junit.Test)3 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)2 ConflictException (co.cask.cdap.common.ConflictException)2