Search in sources :

Example 36 with DatasetSpecificationSummary

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

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

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

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

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

the class IntegrationTestBase method doClear.

private void doClear(NamespaceId namespace, boolean deleteNamespace) throws Exception {
    // stop all programs in the namespace
    getProgramClient().stopAll(namespace);
    if (deleteNamespace) {
        getNamespaceClient().delete(namespace);
        return;
    }
    // delete all apps in the namespace
    for (ApplicationRecord app : getApplicationClient().list(namespace)) {
        getApplicationClient().delete(namespace.app(app.getName(), app.getAppVersion()));
    }
    // delete all dataset instances
    for (DatasetSpecificationSummary datasetSpecSummary : getDatasetClient().list(namespace)) {
        getDatasetClient().delete(namespace.dataset(datasetSpecSummary.getName()));
    }
    ArtifactClient artifactClient = new ArtifactClient(getClientConfig(), getRestClient());
    for (ArtifactSummary artifactSummary : artifactClient.list(namespace, ArtifactScope.USER)) {
        artifactClient.delete(namespace.artifact(artifactSummary.getName(), artifactSummary.getVersion()));
    }
    assertIsClear(namespace);
}
Also used : ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ArtifactClient(io.cdap.cdap.client.ArtifactClient) DatasetSpecificationSummary(io.cdap.cdap.proto.DatasetSpecificationSummary) ApplicationRecord(io.cdap.cdap.proto.ApplicationRecord)

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