Search in sources :

Example 1 with DatasetModuleMeta

use of io.cdap.cdap.proto.DatasetModuleMeta in project cdap by caskdata.

the class ListDatasetTypesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    List<DatasetTypeMeta> datasetTypeMetas = datasetTypeClient.list(cliConfig.getCurrentNamespace());
    Table table = Table.builder().setHeader("name", "modules").setRows(datasetTypeMetas, new RowMaker<DatasetTypeMeta>() {

        @Override
        public List<?> makeRow(DatasetTypeMeta object) {
            List<String> modulesStrings = Lists.newArrayList();
            for (DatasetModuleMeta module : object.getModules()) {
                modulesStrings.add(module.getName());
            }
            return Lists.newArrayList(object.getName(), Joiner.on(", ").join(modulesStrings));
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(io.cdap.cdap.cli.util.table.Table) DatasetModuleMeta(io.cdap.cdap.proto.DatasetModuleMeta) RowMaker(io.cdap.cdap.cli.util.RowMaker) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta)

Example 2 with DatasetModuleMeta

use of io.cdap.cdap.proto.DatasetModuleMeta in project cdap by caskdata.

the class DatasetTypeHandlerTest method testBundledJarModule.

// Tests that a module can be deployed from a jar that is embedded in a bundle jar. This verifies class loading.
@Test
public void testBundledJarModule() throws Exception {
    // Get jar of TestModule1
    Location module1Jar = createModuleJar(TestModule1.class);
    // Create bundle jar with TestModule2 and TestModule1 inside it, request for deploy is made for Module1.
    Assert.assertEquals(200, deployModuleBundled("module1", TestModule1.class.getName(), TestModule2.class, module1Jar));
    Assert.assertEquals(HttpStatus.SC_OK, deleteModules().getResponseCode());
    List<DatasetModuleMeta> modules = getModules().getResponseObject();
    Assert.assertEquals(0, modules.size());
}
Also used : DatasetModuleMeta(io.cdap.cdap.proto.DatasetModuleMeta) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 3 with DatasetModuleMeta

use of io.cdap.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(), actualTypes.stream().map(input -> input == null ? null : input.getName()).collect(Collectors.toList())));
    for (DatasetTypeMeta typeMeta : actualTypes) {
        verify(typeMeta, typeMeta.getName(), typeDependencies.get(typeMeta.getName()));
    }
}
Also used : Iterables(com.google.common.collect.Iterables) TypeToken(com.google.gson.reflect.TypeToken) BeforeClass(org.junit.BeforeClass) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Location(org.apache.twill.filesystem.Location) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) DatasetInstanceConfiguration(io.cdap.cdap.proto.DatasetInstanceConfiguration) HttpResponse(io.cdap.common.http.HttpResponse) HttpStatus(org.apache.http.HttpStatus) HashMap(java.util.HashMap) ObjectResponse(io.cdap.common.http.ObjectResponse) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) DatasetTypeId(io.cdap.cdap.proto.id.DatasetTypeId) HttpRequests(io.cdap.common.http.HttpRequests) DatasetModuleId(io.cdap.cdap.proto.id.DatasetModuleId) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) DatasetModuleMeta(io.cdap.cdap.proto.DatasetModuleMeta) Collection(java.util.Collection) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) File(java.io.File) List(java.util.List) Assert(org.junit.Assert) Collections(java.util.Collections) HttpRequest(io.cdap.common.http.HttpRequest) DatasetModuleMeta(io.cdap.cdap.proto.DatasetModuleMeta) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) HashSet(java.util.HashSet)

Example 4 with DatasetModuleMeta

use of io.cdap.cdap.proto.DatasetModuleMeta in project cdap by caskdata.

the class DefaultDatasetTypeService method delete.

/**
 * Deletes the specified {@link DatasetModuleId}
 */
@Override
public void delete(DatasetModuleId datasetModuleId) throws Exception {
    NamespaceId namespaceId = datasetModuleId.getParent();
    if (NamespaceId.SYSTEM.equals(namespaceId)) {
        throw new UnsupportedOperationException(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);
    }
    try {
        typeManager.deleteModule(datasetModuleId);
    } catch (DatasetModuleConflictException e) {
        throw new DatasetModuleCannotBeDeletedException(datasetModuleId, e.getMessage());
    }
}
Also used : DatasetModuleNotFoundException(io.cdap.cdap.common.DatasetModuleNotFoundException) DatasetModuleConflictException(io.cdap.cdap.data2.datafabric.dataset.type.DatasetModuleConflictException) DatasetModuleMeta(io.cdap.cdap.proto.DatasetModuleMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) DatasetModuleCannotBeDeletedException(io.cdap.cdap.common.DatasetModuleCannotBeDeletedException)

Example 5 with DatasetModuleMeta

use of io.cdap.cdap.proto.DatasetModuleMeta in project cdap by caskdata.

the class DefaultDatasetTypeService method deleteSystemModules.

private void deleteSystemModules() {
    TransactionRunners.run(transactionRunner, context -> {
        DatasetTypeTable datasetTypeTable = DatasetTypeTable.create(context);
        Collection<DatasetModuleMeta> allDatasets = datasetTypeTable.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());
                datasetTypeTable.deleteModule(moduleId);
            }
        }
    });
}
Also used : DatasetModuleId(io.cdap.cdap.proto.id.DatasetModuleId) DatasetModuleMeta(io.cdap.cdap.proto.DatasetModuleMeta) DatasetTypeTable(io.cdap.cdap.data2.datafabric.dataset.service.mds.DatasetTypeTable)

Aggregations

DatasetModuleMeta (io.cdap.cdap.proto.DatasetModuleMeta)20 DatasetModuleId (io.cdap.cdap.proto.id.DatasetModuleId)9 DatasetTypeMeta (io.cdap.cdap.proto.DatasetTypeMeta)6 Location (org.apache.twill.filesystem.Location)5 DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)4 DatasetModuleNotFoundException (io.cdap.cdap.common.DatasetModuleNotFoundException)4 DatasetTypeTable (io.cdap.cdap.data2.datafabric.dataset.service.mds.DatasetTypeTable)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 RowMaker (io.cdap.cdap.cli.util.RowMaker)3 Table (io.cdap.cdap.cli.util.table.Table)3 DatasetInstanceTable (io.cdap.cdap.data2.datafabric.dataset.service.mds.DatasetInstanceTable)3 TypeConflictException (io.cdap.cdap.data2.dataset2.TypeConflictException)3 DatasetTypeId (io.cdap.cdap.proto.id.DatasetTypeId)3 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)3 HttpResponse (io.cdap.common.http.HttpResponse)3 File (java.io.File)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 DatasetDefinitionRegistry (io.cdap.cdap.api.dataset.module.DatasetDefinitionRegistry)2