Search in sources :

Example 11 with DatasetSpecificationSummary

use of io.cdap.cdap.proto.DatasetSpecificationSummary in project cdap by cdapio.

the class LevelDBDatasetMetricsReporter method report.

private void report(Map<TableId, LevelDBTableService.TableStats> datasetStat) throws DatasetManagementException, UnauthorizedException {
    for (Map.Entry<TableId, LevelDBTableService.TableStats> statEntry : datasetStat.entrySet()) {
        String namespace = statEntry.getKey().getNamespace();
        // emit metrics for only user datasets, tables in system namespace are ignored
        if (NamespaceId.SYSTEM.getNamespace().equals(namespace)) {
            continue;
        }
        String tableName = statEntry.getKey().getTableName();
        Collection<DatasetSpecificationSummary> instances = dsFramework.getInstances(new NamespaceId(namespace));
        for (DatasetSpecificationSummary spec : instances) {
            DatasetSpecification specification = dsFramework.getDatasetSpec(new DatasetId(namespace, spec.getName()));
            if (specification.isParent(tableName)) {
                MetricsContext collector = metricsService.getContext(ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, namespace, Constants.Metrics.Tag.DATASET, spec.getName()));
                int sizeInMb = (int) (statEntry.getValue().getDiskSizeBytes() / BYTES_IN_MB);
                collector.gauge("dataset.size.mb", sizeInMb);
                break;
            }
        }
    }
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) MetricsContext(io.cdap.cdap.api.metrics.MetricsContext) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) DatasetSpecificationSummary(io.cdap.cdap.proto.DatasetSpecificationSummary) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) DatasetId(io.cdap.cdap.proto.id.DatasetId)

Example 12 with DatasetSpecificationSummary

use of io.cdap.cdap.proto.DatasetSpecificationSummary in project cdap by cdapio.

the class ListDatasetInstancesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    List<DatasetSpecificationSummary> datasetMetas = datasetClient.list(cliConfig.getCurrentNamespace());
    Table table = Table.builder().setHeader("name", "type", "description").setRows(datasetMetas, new RowMaker<DatasetSpecificationSummary>() {

        @Override
        public List<?> makeRow(DatasetSpecificationSummary object) {
            return Lists.newArrayList(object.getName(), object.getType(), object.getDescription());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) DatasetSpecificationSummary(io.cdap.cdap.proto.DatasetSpecificationSummary)

Example 13 with DatasetSpecificationSummary

use of io.cdap.cdap.proto.DatasetSpecificationSummary in project cdap by cdapio.

the class LocalDatasetDeleterRunnable method run.

@Override
public void run() {
    try {
        List<NamespaceMeta> list = namespaceAdmin.list();
        for (NamespaceMeta namespaceMeta : list) {
            Collection<DatasetSpecificationSummary> specs = datasetFramework.getInstances(namespaceMeta.getNamespaceId(), PROPERTIES);
            if (specs.isEmpty()) {
                // avoid fetching run records
                continue;
            }
            Set<String> activeRuns = getActiveRuns(namespaceMeta.getNamespaceId());
            for (DatasetSpecificationSummary spec : specs) {
                deleteLocalDataset(namespaceMeta.getName(), spec.getName(), activeRuns, spec.getProperties());
            }
        }
    } catch (Throwable t) {
        LOG.warn("Failed to delete the local datasets.", t);
    }
}
Also used : NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) DatasetSpecificationSummary(io.cdap.cdap.proto.DatasetSpecificationSummary)

Example 14 with DatasetSpecificationSummary

use of io.cdap.cdap.proto.DatasetSpecificationSummary in project cdap by cdapio.

the class DatasetClientTestRun method testAll.

@Test
public void testAll() throws Exception {
    DatasetModuleId module = TEST_NAMESPACE.datasetModule(StandaloneDatasetModule.NAME);
    DatasetTypeId type = TEST_NAMESPACE.datasetType(StandaloneDataset.class.getName());
    DatasetModuleId moduleInOtherNamespace = OTHER_NAMESPACE.datasetModule(StandaloneDatasetModule.NAME);
    DatasetTypeId typeInOtherNamespace = OTHER_NAMESPACE.datasetType(StandaloneDataset.class.getName());
    int numBaseModules = moduleClient.list(TEST_NAMESPACE).size();
    int numBaseTypes = typeClient.list(TEST_NAMESPACE).size();
    LOG.info("Adding Dataset module");
    File moduleJarFile = createAppJarFile(StandaloneDatasetModule.class);
    moduleClient.add(TEST_NAMESPACE.datasetModule(StandaloneDatasetModule.NAME), StandaloneDatasetModule.class.getName(), moduleJarFile);
    Assert.assertEquals(numBaseModules + 1, moduleClient.list(TEST_NAMESPACE).size());
    Assert.assertEquals(numBaseTypes + 2, typeClient.list(TEST_NAMESPACE).size());
    LOG.info("Checking that the new Dataset module exists");
    DatasetModuleMeta datasetModuleMeta = moduleClient.get(module);
    Assert.assertNotNull(datasetModuleMeta);
    Assert.assertEquals(StandaloneDatasetModule.NAME, datasetModuleMeta.getName());
    LOG.info("Checking that the new Dataset module does not exist in a different namespace");
    try {
        moduleClient.get(moduleInOtherNamespace);
        Assert.fail("datasetModule found in namespace other than one in which it was expected");
    } catch (DatasetModuleNotFoundException expected) {
    // expected
    }
    LOG.info("Checking that the new Dataset type exists");
    DatasetTypeMeta datasetTypeMeta = typeClient.get(type);
    Assert.assertNotNull(datasetTypeMeta);
    Assert.assertEquals(type.getType(), datasetTypeMeta.getName());
    datasetTypeMeta = typeClient.get(type);
    Assert.assertNotNull(datasetTypeMeta);
    Assert.assertEquals(StandaloneDataset.class.getName(), datasetTypeMeta.getName());
    LOG.info("Checking that the new Dataset type does not exist in a different namespace");
    try {
        typeClient.get(typeInOtherNamespace);
        Assert.fail("datasetType found in namespace other than one in which it was expected");
    } catch (DatasetTypeNotFoundException expected) {
    // expected
    }
    LOG.info("Creating, truncating, and deleting dataset of new Dataset type");
    // Before creating dataset, there are some system datasets already exist
    int numBaseDataset = datasetClient.list(TEST_NAMESPACE).size();
    DatasetId instance = TEST_NAMESPACE.dataset("testDataset");
    String description = "test description";
    datasetClient.create(instance, new DatasetInstanceConfiguration(StandaloneDataset.TYPE_NAME, Collections.<String, String>emptyMap(), description, null));
    Assert.assertEquals(numBaseDataset + 1, datasetClient.list(TEST_NAMESPACE).size());
    // Assert dataset summary for the newly created dataset
    DatasetSpecificationSummary expectedSpec = new DatasetSpecificationSummary(instance.getDataset(), StandaloneDataset.TYPE_NAME, description, Collections.<String, String>emptyMap());
    Assert.assertEquals(expectedSpec, getSpecForDataset(instance, datasetClient.list(TEST_NAMESPACE)));
    datasetClient.truncate(instance);
    DatasetMeta metaBefore = datasetClient.get(instance);
    Assert.assertEquals(0, metaBefore.getSpec().getProperties().size());
    datasetClient.update(instance, ImmutableMap.of("sdf", "foo", "abc", "123"));
    DatasetMeta metaAfter = datasetClient.get(instance);
    Assert.assertEquals(2, metaAfter.getSpec().getProperties().size());
    Assert.assertTrue(metaAfter.getSpec().getProperties().containsKey("sdf"));
    Assert.assertTrue(metaAfter.getSpec().getProperties().containsKey("abc"));
    Assert.assertEquals("foo", metaAfter.getSpec().getProperties().get("sdf"));
    Assert.assertEquals("123", metaAfter.getSpec().getProperties().get("abc"));
    datasetClient.updateExisting(instance, ImmutableMap.of("sdf", "fzz"));
    metaAfter = datasetClient.get(instance);
    Assert.assertEquals(2, metaAfter.getSpec().getProperties().size());
    Assert.assertTrue(metaAfter.getSpec().getProperties().containsKey("sdf"));
    Assert.assertTrue(metaAfter.getSpec().getProperties().containsKey("abc"));
    Assert.assertEquals("fzz", metaAfter.getSpec().getProperties().get("sdf"));
    Assert.assertEquals("123", metaAfter.getSpec().getProperties().get("abc"));
    datasetClient.delete(instance);
    Assert.assertEquals(numBaseDataset, datasetClient.list(TEST_NAMESPACE).size());
    LOG.info("Creating and deleting multiple Datasets");
    for (int i = 1; i <= 3; i++) {
        datasetClient.create(TEST_NAMESPACE.dataset("testDataset" + i), StandaloneDataset.TYPE_NAME);
    }
    Assert.assertEquals(numBaseDataset + 3, datasetClient.list(TEST_NAMESPACE).size());
    for (int i = 1; i <= 3; i++) {
        datasetClient.delete(TEST_NAMESPACE.dataset("testDataset" + i));
    }
    Assert.assertEquals(numBaseDataset, datasetClient.list(TEST_NAMESPACE).size());
    LOG.info("Deleting Dataset module");
    moduleClient.delete(module);
    Assert.assertEquals(numBaseModules, moduleClient.list(TEST_NAMESPACE).size());
    Assert.assertEquals(numBaseTypes, typeClient.list(TEST_NAMESPACE).size());
    LOG.info("Adding Dataset module and then deleting all Dataset modules");
    moduleClient.add(TEST_NAMESPACE.datasetModule("testModule1"), StandaloneDatasetModule.class.getName(), moduleJarFile);
    Assert.assertEquals(numBaseModules + 1, moduleClient.list(TEST_NAMESPACE).size());
    Assert.assertEquals(numBaseTypes + 2, typeClient.list(TEST_NAMESPACE).size());
    moduleClient.deleteAll(TEST_NAMESPACE);
    Assert.assertEquals(numBaseModules, moduleClient.list(TEST_NAMESPACE).size());
    Assert.assertEquals(numBaseTypes, typeClient.list(TEST_NAMESPACE).size());
}
Also used : DatasetTypeId(io.cdap.cdap.proto.id.DatasetTypeId) StandaloneDatasetModule(io.cdap.cdap.client.app.StandaloneDatasetModule) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) DatasetMeta(io.cdap.cdap.proto.DatasetMeta) DatasetInstanceConfiguration(io.cdap.cdap.proto.DatasetInstanceConfiguration) DatasetSpecificationSummary(io.cdap.cdap.proto.DatasetSpecificationSummary) DatasetId(io.cdap.cdap.proto.id.DatasetId) DatasetModuleNotFoundException(io.cdap.cdap.common.DatasetModuleNotFoundException) DatasetModuleId(io.cdap.cdap.proto.id.DatasetModuleId) DatasetModuleMeta(io.cdap.cdap.proto.DatasetModuleMeta) StandaloneDataset(io.cdap.cdap.client.app.StandaloneDataset) DatasetTypeNotFoundException(io.cdap.cdap.common.DatasetTypeNotFoundException) File(java.io.File) Test(org.junit.Test)

Example 15 with DatasetSpecificationSummary

use of io.cdap.cdap.proto.DatasetSpecificationSummary in project cdap by cdapio.

the class DatasetClient method list.

/**
 * Lists all datasets.
 *
 * @return list of {@link DatasetSpecificationSummary}.
 * @throws IOException if a network error occurred
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 */
public List<DatasetSpecificationSummary> list(NamespaceId namespace) throws IOException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(namespace, "data/datasets");
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
    return ObjectResponse.fromJsonBody(response, new TypeToken<List<DatasetSpecificationSummary>>() {
    }).getResponseObject();
}
Also used : TypeToken(com.google.common.reflect.TypeToken) HttpResponse(io.cdap.common.http.HttpResponse) DatasetSpecificationSummary(io.cdap.cdap.proto.DatasetSpecificationSummary) URL(java.net.URL)

Aggregations

DatasetSpecificationSummary (io.cdap.cdap.proto.DatasetSpecificationSummary)38 DatasetId (io.cdap.cdap.proto.id.DatasetId)16 Test (org.junit.Test)14 DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)10 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 DatasetMeta (io.cdap.cdap.proto.DatasetMeta)6 ProgramId (io.cdap.cdap.proto.id.ProgramId)6 File (java.io.File)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)4 DatasetProperties (io.cdap.cdap.api.dataset.DatasetProperties)4 MetricsContext (io.cdap.cdap.api.metrics.MetricsContext)4 DatasetClient (io.cdap.cdap.client.DatasetClient)4 DatasetModuleMeta (io.cdap.cdap.proto.DatasetModuleMeta)4 RunRecord (io.cdap.cdap.proto.RunRecord)4 IOException (java.io.IOException)4 TableId (io.cdap.cdap.data2.util.TableId)3 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)3