Search in sources :

Example 1 with DatasetInstanceConfiguration

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

the class ConversionHelpers method getInstanceConfiguration.

static DatasetInstanceConfiguration getInstanceConfiguration(HttpRequest request) throws BadRequestException {
    Reader reader = new InputStreamReader(new ChannelBufferInputStream(request.getContent()), Charsets.UTF_8);
    try {
        DatasetInstanceConfiguration config = GSON.fromJson(reader, DatasetInstanceConfiguration.class);
        Preconditions.checkNotNull(config.getTypeName(), "The typeName must be specified.");
        return config;
    } catch (JsonSyntaxException | NullPointerException e) {
        throw new BadRequestException(e.getMessage());
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BadRequestException(co.cask.cdap.common.BadRequestException) ChannelBufferInputStream(org.jboss.netty.buffer.ChannelBufferInputStream) DatasetInstanceConfiguration(co.cask.cdap.proto.DatasetInstanceConfiguration)

Example 2 with DatasetInstanceConfiguration

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

the class DatasetInstanceHandlerTest method createInstance.

private HttpResponse createInstance(DatasetId instance, String typeName, @Nullable String description, @Nullable DatasetProperties props, @Nullable String ownerPrincipal) throws IOException {
    DatasetInstanceConfiguration creationProperties;
    if (props != null) {
        creationProperties = new DatasetInstanceConfiguration(typeName, props.getProperties(), description, ownerPrincipal);
    } else {
        creationProperties = new DatasetInstanceConfiguration(typeName, null, description, ownerPrincipal);
    }
    HttpRequest request = HttpRequest.put(getUrl(instance.getNamespace(), "/data/datasets/" + instance.getEntityName())).withBody(GSON.toJson(creationProperties)).build();
    return HttpRequests.execute(request);
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) DatasetInstanceConfiguration(co.cask.cdap.proto.DatasetInstanceConfiguration)

Example 3 with DatasetInstanceConfiguration

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

the class DatasetTypeHandlerTest method testBasics.

@Test
public void testBasics() throws Exception {
    // nothing has been deployed, modules and types list is empty
    verifyAll(NO_MODULES, NO_DEPENDENCIES);
    // deploy module and verify that it can be retrieved in all ways
    Assert.assertEquals(HttpStatus.SC_OK, deployModule("module1", TestModule1x.class).getResponseCode());
    verifyAll(ONLY_MODULE1X, ONLY_1X_DEPENDENCIES);
    // cannot deploy other module with same types
    Assert.assertEquals(HttpStatus.SC_CONFLICT, deployModule("not-module1", TestModule1.class).getResponseCode());
    verifyAll(ONLY_MODULE1X, ONLY_1X_DEPENDENCIES);
    // can deploy same module again
    Assert.assertEquals(HttpStatus.SC_OK, deployModule("module1", TestModule1x.class).getResponseCode());
    verifyAll(ONLY_MODULE1X, ONLY_1X_DEPENDENCIES);
    // create a dataset instance, verify that we cannot redeploy the module with fewer types, even with force option
    instanceService.create(NamespaceId.DEFAULT.getNamespace(), "instance1x", new DatasetInstanceConfiguration("datasetType1x", new HashMap<String, String>()));
    Assert.assertEquals(HttpStatus.SC_CONFLICT, deployModule("module1", TestModule1.class).getResponseCode());
    Assert.assertEquals(HttpStatus.SC_CONFLICT, deployModule("module1", TestModule1.class, true).getResponseCode());
    verifyAll(ONLY_MODULE1X, ONLY_1X_DEPENDENCIES);
    // drop the instance, now we should be able to redeploy, dropping type1x
    instanceService.drop(NamespaceId.DEFAULT.dataset("instance1x"));
    Assert.assertEquals(HttpStatus.SC_OK, deployModule("module1", TestModule1.class).getResponseCode());
    verifyAll(ONLY_MODULE1, ONLY_1_DEPENDENCIES);
    // redeploy module with more types and validate
    Assert.assertEquals(HttpStatus.SC_OK, deployModule("module1", TestModule1x.class).getResponseCode());
    verifyAll(ONLY_MODULE1X, ONLY_1X_DEPENDENCIES);
    // deploy another module which depends on the first one
    Assert.assertEquals(HttpStatus.SC_OK, deployModule("module2", TestModule2.class).getResponseCode());
    verifyAll(MODULES_1X_AND_2, BOTH_1X_2_DEPENDENCIES);
    // cannot delete non-existent module
    Assert.assertEquals(HttpStatus.SC_NOT_FOUND, deleteModule("non-existing-module").getResponseCode());
    // cannot delete module1 since module2 depends on it, verify that nothing has been deleted
    Assert.assertEquals(HttpStatus.SC_CONFLICT, deleteModule("module1").getResponseCode());
    verifyAll(MODULES_1X_AND_2, BOTH_1X_2_DEPENDENCIES);
    // cannot deploy same module again with fewer types (because module2 depends on it)
    Assert.assertEquals(HttpStatus.SC_CONFLICT, deployModule("module1", TestModule1.class).getResponseCode());
    verifyAll(MODULES_1X_AND_2, BOTH_1X_2_DEPENDENCIES);
    // create dataset instances, try force deploy of same module again with fewer types - should fail
    instanceService.create(NamespaceId.DEFAULT.getNamespace(), "instance1", new DatasetInstanceConfiguration("datasetType1", new HashMap<String, String>()));
    instanceService.create(NamespaceId.DEFAULT.getNamespace(), "instance1x", new DatasetInstanceConfiguration("datasetType1x", new HashMap<String, String>()));
    Assert.assertEquals(HttpStatus.SC_CONFLICT, deployModule("module1", TestModule1.class, true).getResponseCode());
    verifyAll(MODULES_1X_AND_2, BOTH_1X_2_DEPENDENCIES);
    // drop the instance of type1x, now forced deploy should work
    instanceService.drop(NamespaceId.DEFAULT.dataset("instance1x"));
    Assert.assertEquals(HttpStatus.SC_OK, deployModule("module1", TestModule1.class, true).getResponseCode());
    verifyAll(MODULES_1_AND_2, BOTH_1_2_DEPENDENCIES);
    // delete module2, should be removed from usedBy list everywhere and all its types should no longer be available
    Assert.assertEquals(HttpStatus.SC_OK, deleteModule("module2").getResponseCode());
    Assert.assertEquals(HttpStatus.SC_NOT_FOUND, getMissingType("datasetType2").getResponseCode());
    verifyAll(ONLY_MODULE1, ONLY_1_DEPENDENCIES);
    // cannot delete module2 again
    Assert.assertEquals(HttpStatus.SC_NOT_FOUND, deleteModule("module2").getResponseCode());
    // cannot delete module 1 becuse there is an instance
    Assert.assertEquals(HttpStatus.SC_CONFLICT, deleteModules().getResponseCode());
    verifyAll(ONLY_MODULE1, ONLY_1_DEPENDENCIES);
    // drop the instance of type1, now delete of module1 should work
    instanceService.drop(NamespaceId.DEFAULT.dataset("instance1"));
    Assert.assertEquals(HttpStatus.SC_OK, deleteModules().getResponseCode());
    Assert.assertEquals(HttpStatus.SC_NOT_FOUND, getMissingType("datasetType1").getResponseCode());
    verifyAll(NO_MODULES, NO_DEPENDENCIES);
}
Also used : HashMap(java.util.HashMap) DatasetInstanceConfiguration(co.cask.cdap.proto.DatasetInstanceConfiguration) Test(org.junit.Test)

Example 4 with DatasetInstanceConfiguration

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

the class DatasetInstanceServiceTest method testInstanceMetaCache.

@Test
public void testInstanceMetaCache() throws Exception {
    // deploy a dataset
    instanceService.create(NamespaceId.DEFAULT.getEntityName(), "testds", new DatasetInstanceConfiguration("table", new HashMap<String, String>()));
    // get the dataset meta for two different owners, assert it is the same
    DatasetMeta meta = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app1", ProgramType.FLOW, "flow1")));
    DatasetMeta met2 = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app2", ProgramType.FLOW, "flow2")));
    Assert.assertSame(meta, met2);
    // update the dataset
    instanceService.update(NamespaceId.DEFAULT.dataset("testds"), ImmutableMap.of("ttl", "12345678"));
    // get the dataset meta, validate it changed
    met2 = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app2", ProgramType.FLOW, "flow2")));
    Assert.assertNotSame(meta, met2);
    Assert.assertEquals("12345678", met2.getSpec().getProperty("ttl"));
    // delete the dataset
    instanceService.drop(NamespaceId.DEFAULT.dataset("testds"));
    // get the dataset meta, validate not found
    try {
        instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app1", ProgramType.FLOW, "flow2")));
        Assert.fail("get() should have thrown NotFoundException");
    } catch (NotFoundException e) {
    // expected
    }
    // recreate the dataset
    instanceService.create(NamespaceId.DEFAULT.getNamespace(), "testds", new DatasetInstanceConfiguration("table", new HashMap<String, String>()));
    // get the dataset meta, validate it is up to date
    met2 = instanceService.get(NamespaceId.DEFAULT.dataset("testds"), ImmutableList.<EntityId>of(new ProgramId(NamespaceId.DEFAULT.getNamespace(), "app2", ProgramType.FLOW, "flow2")));
    Assert.assertEquals(meta.getSpec(), met2.getSpec());
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) HashMap(java.util.HashMap) DatasetMeta(co.cask.cdap.proto.DatasetMeta) NotFoundException(co.cask.cdap.common.NotFoundException) DatasetInstanceConfiguration(co.cask.cdap.proto.DatasetInstanceConfiguration) ProgramId(co.cask.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 5 with DatasetInstanceConfiguration

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

the class IntegrationTestManager method addDatasetInstance.

@Override
public <T extends DatasetAdmin> T addDatasetInstance(String datasetType, DatasetId datasetId, DatasetProperties props) throws Exception {
    DatasetInstanceConfiguration dsConf = new DatasetInstanceConfiguration(datasetType, props.getProperties(), props.getDescription(), null);
    datasetClient.create(datasetId, dsConf);
    return (T) new RemoteDatasetAdmin(datasetClient, datasetId, dsConf);
}
Also used : DatasetInstanceConfiguration(co.cask.cdap.proto.DatasetInstanceConfiguration)

Aggregations

DatasetInstanceConfiguration (co.cask.cdap.proto.DatasetInstanceConfiguration)14 Test (org.junit.Test)6 DatasetId (co.cask.cdap.proto.id.DatasetId)4 DatasetTypeNotFoundException (co.cask.cdap.common.DatasetTypeNotFoundException)3 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)3 NamespaceId (co.cask.cdap.proto.id.NamespaceId)3 StreamId (co.cask.cdap.proto.id.StreamId)3 MetadataSearchResultRecord (co.cask.cdap.proto.metadata.MetadataSearchResultRecord)3 FormatSpecification (co.cask.cdap.api.data.format.FormatSpecification)2 BadRequestException (co.cask.cdap.common.BadRequestException)2 DatasetAlreadyExistsException (co.cask.cdap.common.DatasetAlreadyExistsException)2 HandlerException (co.cask.cdap.common.HandlerException)2 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)2 DatasetMeta (co.cask.cdap.proto.DatasetMeta)2 ViewSpecification (co.cask.cdap.proto.ViewSpecification)2 EntityTypeSimpleName (co.cask.cdap.proto.element.EntityTypeSimpleName)2 StreamViewId (co.cask.cdap.proto.id.StreamViewId)2 MetadataSearchResponse (co.cask.cdap.proto.metadata.MetadataSearchResponse)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 InputStreamReader (java.io.InputStreamReader)2