Search in sources :

Example 16 with ViewSpecification

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

the class StreamViewHttpHandlerTest method testAll.

@Test
public void testAll() throws Exception {
    execute(404, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views")).build());
    execute(404, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views/view1")).build());
    execute(404, HttpRequest.delete(resolve("/v3/namespaces/default/streams/foo/views/view1")).build());
    execute(200, HttpRequest.put(resolve("/v3/namespaces/default/streams/foo")).build());
    execute(404, HttpRequest.delete(resolve("/v3/namespaces/default/streams/foo/views/nonexistent")).build());
    List<String> views = execute(200, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views")).build(), new TypeToken<List<String>>() {
    }.getType());
    Assert.assertEquals(ImmutableList.of(), views);
    Schema schema = Schema.recordOf("foo", Schema.Field.of("name", Schema.of(Schema.Type.STRING)));
    FormatSpecification formatSpec = new FormatSpecification(Formats.AVRO, schema, Collections.<String, String>emptyMap());
    ViewSpecification config = new ViewSpecification(formatSpec);
    // trying to create without request body should give 400
    execute(400, HttpRequest.put(resolve("/v3/namespaces/default/streams/foo/views/view1")).build());
    execute(201, HttpRequest.put(resolve("/v3/namespaces/default/streams/foo/views/view1")).withBody(GSON.toJson(config)).build());
    ViewDetail actualDetail = execute(200, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views/view1")).build(), ViewDetail.class);
    Assert.assertEquals(new ViewDetail("view1", new ViewSpecification(config.getFormat(), "stream_foo_view1")), actualDetail);
    views = execute(200, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views")).build(), new TypeToken<List<String>>() {
    }.getType());
    Assert.assertEquals(ImmutableList.of("view1"), views);
    execute(201, HttpRequest.put(resolve("/v3/namespaces/default/streams/foo/views/view2")).withBody(GSON.toJson(config)).build());
    actualDetail = execute(200, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views/view2")).build(), ViewDetail.class);
    Assert.assertEquals(new ViewDetail("view2", new ViewSpecification(config.getFormat(), "stream_foo_view2")), actualDetail);
    views = execute(200, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views")).build(), new TypeToken<List<String>>() {
    }.getType());
    Assert.assertEquals(ImmutableList.of("view1", "view2"), views == null ? null : Ordering.natural().sortedCopy(views));
    execute(200, HttpRequest.delete(resolve("/v3/namespaces/default/streams/foo/views/view1")).build());
    views = execute(200, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views")).build(), new TypeToken<List<String>>() {
    }.getType());
    Assert.assertEquals(ImmutableList.of("view2"), views);
    execute(200, HttpRequest.delete(resolve("/v3/namespaces/default/streams/foo/views/view2")).build());
    views = execute(200, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views")).build(), new TypeToken<List<String>>() {
    }.getType());
    Assert.assertEquals(ImmutableList.<String>of(), views);
    // Deleting a stream should also delete the associated views
    execute(200, HttpRequest.delete(resolve("/v3/namespaces/default/streams/foo")).build());
    execute(200, HttpRequest.put(resolve("/v3/namespaces/default/streams/foo")).build());
    execute(404, HttpRequest.get(resolve("/v3/namespaces/default/streams/foo/views/view1")).build());
}
Also used : TypeToken(com.google.common.reflect.TypeToken) Schema(co.cask.cdap.api.data.schema.Schema) FormatSpecification(co.cask.cdap.api.data.format.FormatSpecification) ViewSpecification(co.cask.cdap.proto.ViewSpecification) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ViewDetail(co.cask.cdap.proto.ViewDetail) Test(org.junit.Test)

Example 17 with ViewSpecification

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

the class ViewAdmin method createOrUpdate.

public boolean createOrUpdate(StreamViewId viewId, ViewSpecification spec) throws Exception {
    try {
        ViewSpecification previousSpec = store.get(viewId);
        if (spec.getTableName() == null) {
            // use the previous table name
            spec = new ViewSpecification(spec.getFormat(), previousSpec.getTableName());
        } else if (!spec.getTableName().equals(previousSpec.getTableName())) {
            throw new IllegalArgumentException(String.format("Cannot change table name for view %s", viewId));
        }
        explore.disableExploreStream(viewId.getParent(), previousSpec.getTableName());
    } catch (NotFoundException e) {
    // pass through
    }
    if (spec.getTableName() == null) {
        spec = new ViewSpecification(spec.getFormat(), naming.getTableName(viewId));
    }
    explore.enableExploreStream(viewId.getParent(), spec.getTableName(), spec.getFormat());
    boolean result = store.createOrUpdate(viewId, spec);
    ViewSystemMetadataWriter systemMetadataWriter = new ViewSystemMetadataWriter(metadataStore, viewId, spec, !result);
    systemMetadataWriter.write();
    return result;
}
Also used : ViewSystemMetadataWriter(co.cask.cdap.data2.metadata.system.ViewSystemMetadataWriter) ViewSpecification(co.cask.cdap.proto.ViewSpecification) NotFoundException(co.cask.cdap.common.NotFoundException)

Example 18 with ViewSpecification

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

the class StreamClientTestRun method testStreamDeleteAfterCreatingView.

@Test
public void testStreamDeleteAfterCreatingView() throws Exception {
    StreamId testStream = NamespaceId.DEFAULT.stream("testStream");
    streamClient.create(testStream);
    // should throw StreamNotFoundException if the stream has not been successfully created in the previous step
    streamClient.getConfig(testStream);
    StreamViewClient streamViewClient = new StreamViewClient(clientConfig);
    StreamViewId testView = testStream.view("testView");
    ViewSpecification testViewSpec = new ViewSpecification(new FormatSpecification("csv", null, null));
    Assert.assertTrue(streamViewClient.createOrUpdate(testView, testViewSpec));
    // test stream delete
    streamClient.delete(testStream);
    // recreate the stream and the view
    streamClient.create(testStream);
    // should throw StreamNotFoundException if the stream has not been successfully created in the previous step
    streamClient.getConfig(testStream);
    Assert.assertTrue(streamViewClient.createOrUpdate(testView, testViewSpec));
    // test that namespace deletion succeeds
    namespaceClient.delete(NamespaceId.DEFAULT);
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) FormatSpecification(co.cask.cdap.api.data.format.FormatSpecification) ViewSpecification(co.cask.cdap.proto.ViewSpecification) StreamViewId(co.cask.cdap.proto.id.StreamViewId) Test(org.junit.Test)

Aggregations

ViewSpecification (co.cask.cdap.proto.ViewSpecification)18 FormatSpecification (co.cask.cdap.api.data.format.FormatSpecification)14 StreamViewId (co.cask.cdap.proto.id.StreamViewId)12 StreamId (co.cask.cdap.proto.id.StreamId)10 Test (org.junit.Test)9 DatasetId (co.cask.cdap.proto.id.DatasetId)6 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)5 NamespaceId (co.cask.cdap.proto.id.NamespaceId)5 MetadataSearchResultRecord (co.cask.cdap.proto.metadata.MetadataSearchResultRecord)5 Schema (co.cask.cdap.api.data.schema.Schema)4 NotFoundException (co.cask.cdap.common.NotFoundException)3 ApplicationId (co.cask.cdap.proto.id.ApplicationId)3 ArtifactId (co.cask.cdap.proto.id.ArtifactId)3 WordCountApp (co.cask.cdap.WordCountApp)2 DatasetInstanceConfiguration (co.cask.cdap.proto.DatasetInstanceConfiguration)2 ViewDetail (co.cask.cdap.proto.ViewDetail)2 EntityTypeSimpleName (co.cask.cdap.proto.element.EntityTypeSimpleName)2 ProgramId (co.cask.cdap.proto.id.ProgramId)2 Config (co.cask.cdap.api.Config)1 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)1