Search in sources :

Example 1 with DatasetSpecificationSummary

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

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 2 with DatasetSpecificationSummary

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

the class DatasetInstanceHandlerTest method testUpdateInstance.

@Test
public void testUpdateInstance() throws Exception {
    // nothing has been created, modules and types list is empty
    List<DatasetSpecificationSummary> instances = getInstances().getResponseObject();
    // nothing in the beginning
    Assert.assertEquals(0, instances.size());
    try {
        DatasetProperties props = DatasetProperties.builder().add("prop1", "val1").add(TestModule2.NOT_RECONFIGURABLE, "this").build();
        // deploy modules
        deployModule("module1", TestModule1.class);
        deployModule("module2", TestModule2.class);
        // create dataset instance
        Assert.assertEquals(HttpStatus.SC_OK, createInstance("dataset1", "datasetType2", props).getResponseCode());
        // verify instance was created
        instances = getInstances().getResponseObject();
        Assert.assertEquals(1, instances.size());
        DatasetMeta meta = getInstanceObject("dataset1").getResponseObject();
        Map<String, String> storedOriginalProps = meta.getSpec().getOriginalProperties();
        Assert.assertEquals(props.getProperties(), storedOriginalProps);
        Map<String, String> retrievedProps = getInstanceProperties("dataset1").getResponseObject();
        Assert.assertEquals(props.getProperties(), retrievedProps);
        // these properties are incompatible because TestModule1.NOT_RECONFIGURABLE may not change
        DatasetProperties newProps = DatasetProperties.builder().add("prop2", "val2").add(TestModule2.NOT_RECONFIGURABLE, "that").build();
        Assert.assertEquals(HttpStatus.SC_CONFLICT, updateInstance("dataset1", newProps).getResponseCode());
        // update dataset instance with valid properties
        newProps = DatasetProperties.builder().add("prop2", "val2").add(TestModule2.NOT_RECONFIGURABLE, "this").build();
        Assert.assertEquals(HttpStatus.SC_OK, updateInstance("dataset1", newProps).getResponseCode());
        meta = getInstanceObject("dataset1").getResponseObject();
        Assert.assertEquals(newProps.getProperties(), meta.getSpec().getOriginalProperties());
        Assert.assertEquals("val2", meta.getSpec().getProperty("prop2"));
        Assert.assertNull(meta.getSpec().getProperty("prop1"));
        retrievedProps = getInstanceProperties("dataset1").getResponseObject();
        Assert.assertEquals(newProps.getProperties(), retrievedProps);
    } finally {
        // delete dataset instance
        Assert.assertEquals(HttpStatus.SC_OK, deleteInstance("dataset1").getResponseCode());
        Assert.assertEquals(0, getInstances().getResponseObject().size());
        // delete dataset modules
        Assert.assertEquals(HttpStatus.SC_OK, deleteModule("module2").getResponseCode());
        Assert.assertEquals(HttpStatus.SC_OK, deleteModule("module1").getResponseCode());
    }
}
Also used : DatasetProperties(io.cdap.cdap.api.dataset.DatasetProperties) DatasetMeta(io.cdap.cdap.proto.DatasetMeta) DatasetSpecificationSummary(io.cdap.cdap.proto.DatasetSpecificationSummary) Test(org.junit.Test)

Example 3 with DatasetSpecificationSummary

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

the class ConversionHelpers method spec2Summary.

static Collection<DatasetSpecificationSummary> spec2Summary(Collection<DatasetSpecification> specs) {
    List<DatasetSpecificationSummary> datasetSummaries = Lists.newArrayList();
    for (DatasetSpecification spec : specs) {
        // TODO: (CDAP-3097) handle system datasets specially within a namespace instead of filtering them out
        // by the handler. This filter is only in the list endpoint because the other endpoints are used by
        // HBaseQueueAdmin through DatasetFramework.
        spec = DatasetsUtil.fixOriginalProperties(spec);
        datasetSummaries.add(new DatasetSpecificationSummary(spec.getName(), spec.getType(), spec.getDescription(), spec.getOriginalProperties()));
    }
    return datasetSummaries;
}
Also used : DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetSpecificationSummary(io.cdap.cdap.proto.DatasetSpecificationSummary)

Example 4 with DatasetSpecificationSummary

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

the class InMemoryDatasetFramework method getInstances.

@Override
public Collection<DatasetSpecificationSummary> getInstances(NamespaceId namespaceId, Map<String, String> properties) {
    readLock.lock();
    try {
        // don't expect this to be called a lot.
        // might be better to maintain this collection separately and just return it, but seems like its not worth it.
        Collection<DatasetSpecification> specs = instances.row(namespaceId).values();
        ImmutableList.Builder<DatasetSpecificationSummary> specSummaries = ImmutableList.builder();
        for (DatasetSpecification spec : specs) {
            if (properties.isEmpty() || Maps.difference(properties, spec.getProperties()).entriesOnlyOnLeft().isEmpty()) {
                specSummaries.add(new DatasetSpecificationSummary(spec.getName(), spec.getType(), spec.getProperties()));
            }
        }
        return specSummaries.build();
    } finally {
        readLock.unlock();
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetSpecificationSummary(io.cdap.cdap.proto.DatasetSpecificationSummary)

Example 5 with DatasetSpecificationSummary

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

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)19 DatasetId (io.cdap.cdap.proto.id.DatasetId)8 Test (org.junit.Test)7 DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)5 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 DatasetMeta (io.cdap.cdap.proto.DatasetMeta)3 ProgramId (io.cdap.cdap.proto.id.ProgramId)3 File (java.io.File)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)2 DatasetProperties (io.cdap.cdap.api.dataset.DatasetProperties)2 MetricsContext (io.cdap.cdap.api.metrics.MetricsContext)2 DatasetClient (io.cdap.cdap.client.DatasetClient)2 TableId (io.cdap.cdap.data2.util.TableId)2 DatasetModuleMeta (io.cdap.cdap.proto.DatasetModuleMeta)2 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)2 RunRecord (io.cdap.cdap.proto.RunRecord)2 IOException (java.io.IOException)2