Search in sources :

Example 1 with ViewDetail

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

the class StreamViewClient method get.

/**
 * Gets detailed information about a view.
 *
 * @param id the view
 * @return the detailed information about the view
 * @throws NotFoundException if the view was not found
 */
public ViewDetail get(StreamViewId id) throws NotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(id.getParent().getParent(), String.format("streams/%s/views/%s", id.getStream(), id.getView()));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(id);
    }
    return ObjectResponse.fromJsonBody(response, ViewDetail.class, GSON).getResponseObject();
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) NotFoundException(co.cask.cdap.common.NotFoundException) URL(java.net.URL) ViewDetail(co.cask.cdap.proto.ViewDetail)

Example 2 with ViewDetail

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

the class StreamViewClientTest method testAll.

@Test
public void testAll() throws Exception {
    NamespaceId namespace = NamespaceId.DEFAULT;
    StreamId stream = namespace.stream("foo");
    StreamViewId view1 = stream.view("view1");
    LOG.info("Creating stream {}", stream);
    streamClient.create(stream);
    try {
        LOG.info("Sending events to stream {}", stream);
        streamClient.sendEvent(stream, "a,b,c");
        streamClient.sendEvent(stream, "d,e,f");
        streamClient.sendEvent(stream, "g,h,i");
        LOG.info("Verifying that no views exist yet");
        Assert.assertEquals(ImmutableList.of(), streamViewClient.list(stream));
        try {
            streamViewClient.get(view1);
            Assert.fail();
        } catch (NotFoundException e) {
            Assert.assertEquals(view1, e.getObject());
        }
        FormatSpecification format = new FormatSpecification("csv", Schema.recordOf("foo", Schema.Field.of("one", Schema.of(Schema.Type.STRING)), Schema.Field.of("two", Schema.of(Schema.Type.STRING)), Schema.Field.of("three", Schema.of(Schema.Type.STRING))));
        ViewSpecification viewSpecification = new ViewSpecification(format, "firsttable");
        LOG.info("Creating view {} with config {}", view1, GSON.toJson(viewSpecification));
        Assert.assertEquals(true, streamViewClient.createOrUpdate(view1, viewSpecification));
        LOG.info("Verifying that view {} has been created", view1);
        Assert.assertEquals(new ViewDetail(view1.getView(), viewSpecification), streamViewClient.get(view1));
        Assert.assertEquals(ImmutableList.of(view1.getView()), streamViewClient.list(stream));
        FormatSpecification newFormat = new FormatSpecification("csv", Schema.recordOf("foo", Schema.Field.of("one", Schema.of(Schema.Type.STRING)), Schema.Field.of("two", Schema.of(Schema.Type.STRING)), Schema.Field.of("three", Schema.of(Schema.Type.STRING))));
        ViewSpecification newViewSpecification = new ViewSpecification(newFormat, "firsttable");
        LOG.info("Updating view {} with config {}", view1, GSON.toJson(newViewSpecification));
        Assert.assertEquals(false, streamViewClient.createOrUpdate(view1, newViewSpecification));
        LOG.info("Verifying that view {} has been updated", view1);
        Assert.assertEquals(new ViewDetail(view1.getView(), newViewSpecification), streamViewClient.get(view1));
        Assert.assertEquals(ImmutableList.of(view1.getView()), streamViewClient.list(stream));
        ExploreExecutionResult executionResult = queryClient.execute(view1.getParent().getParent(), "select one,two,three from firsttable").get();
        Assert.assertNotNull(executionResult.getResultSchema());
        Assert.assertEquals(3, executionResult.getResultSchema().size());
        Assert.assertEquals("one", executionResult.getResultSchema().get(0).getName());
        Assert.assertEquals("two", executionResult.getResultSchema().get(1).getName());
        Assert.assertEquals("three", executionResult.getResultSchema().get(2).getName());
        List<QueryResult> results = Lists.newArrayList(executionResult);
        Assert.assertNotNull(results);
        Assert.assertEquals(3, results.size());
        Assert.assertEquals("a", results.get(0).getColumns().get(0));
        Assert.assertEquals("b", results.get(0).getColumns().get(1));
        Assert.assertEquals("c", results.get(0).getColumns().get(2));
        Assert.assertEquals("d", results.get(1).getColumns().get(0));
        Assert.assertEquals("e", results.get(1).getColumns().get(1));
        Assert.assertEquals("f", results.get(1).getColumns().get(2));
        Assert.assertEquals("g", results.get(2).getColumns().get(0));
        Assert.assertEquals("h", results.get(2).getColumns().get(1));
        Assert.assertEquals("i", results.get(2).getColumns().get(2));
        LOG.info("Deleting view {}", view1);
        streamViewClient.delete(view1);
        LOG.info("Verifying that view {] has been deleted", view1);
        try {
            streamViewClient.get(view1);
            Assert.fail();
        } catch (NotFoundException e) {
            Assert.assertEquals(view1, e.getObject());
        }
        Assert.assertEquals(ImmutableList.of(), streamViewClient.list(stream));
    } finally {
        streamClient.delete(stream);
    }
    // test deleting stream with a view
    LOG.info("Creating stream {}", stream);
    streamClient.create(stream);
    try {
        FormatSpecification format = new FormatSpecification("csv", Schema.recordOf("foo", Schema.Field.of("one", Schema.of(Schema.Type.STRING)), Schema.Field.of("two", Schema.of(Schema.Type.STRING)), Schema.Field.of("three", Schema.of(Schema.Type.STRING))));
        ViewSpecification viewSpecification = new ViewSpecification(format, "firsttable");
        LOG.info("Creating view {} with config {}", view1, GSON.toJson(viewSpecification));
        Assert.assertEquals(true, streamViewClient.createOrUpdate(view1, viewSpecification));
    } finally {
        streamClient.delete(stream);
    }
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) QueryResult(co.cask.cdap.proto.QueryResult) FormatSpecification(co.cask.cdap.api.data.format.FormatSpecification) NotFoundException(co.cask.cdap.common.NotFoundException) ViewSpecification(co.cask.cdap.proto.ViewSpecification) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ExploreExecutionResult(co.cask.cdap.explore.client.ExploreExecutionResult) ViewDetail(co.cask.cdap.proto.ViewDetail) StreamViewId(co.cask.cdap.proto.id.StreamViewId) Test(org.junit.Test)

Example 3 with ViewDetail

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

the class DescribeStreamViewCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    StreamId streamId = cliConfig.getCurrentNamespace().stream(arguments.get(ArgumentName.STREAM.toString()));
    ViewDetail detail = client.get(streamId.view(arguments.get(ArgumentName.VIEW.toString())));
    Table table = Table.builder().setHeader("id", "format", "table", "schema", "settings").setRows(Collections.singletonList(detail), new RowMaker<ViewDetail>() {

        @Override
        public List<?> makeRow(ViewDetail object) {
            return Lists.newArrayList(object.getId(), object.getFormat().getName(), object.getTableName(), GSON.toJson(object.getFormat().getSchema()), GSON.toJson(object.getFormat().getSettings()));
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) ViewDetail(co.cask.cdap.proto.ViewDetail)

Example 4 with ViewDetail

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

the class InMemoryViewStore method get.

@Override
public ViewDetail get(StreamViewId viewId) throws NotFoundException {
    Lock lock = viewsLock.readLock();
    lock.lock();
    try {
        if (!views.containsRow(viewId)) {
            throw new NotFoundException(viewId);
        }
        return new ViewDetail(viewId.getEntityName(), views.get(viewId, viewId.getParent()));
    } finally {
        lock.unlock();
    }
}
Also used : NotFoundException(co.cask.cdap.common.NotFoundException) ViewDetail(co.cask.cdap.proto.ViewDetail) Lock(java.util.concurrent.locks.Lock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 5 with ViewDetail

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

the class StreamViewHttpHandler method get.

@GET
@Path("/streams/{stream}/views/{view}")
public void get(HttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("stream") String stream, @PathParam("view") String view) throws Exception {
    StreamViewId viewId = new StreamViewId(namespace, stream, view);
    ViewDetail detail = new ViewDetail(viewId.getEntityName(), admin.getView(viewId));
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(detail, ViewDetail.class));
}
Also used : ViewDetail(co.cask.cdap.proto.ViewDetail) StreamViewId(co.cask.cdap.proto.id.StreamViewId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

ViewDetail (co.cask.cdap.proto.ViewDetail)6 NotFoundException (co.cask.cdap.common.NotFoundException)3 FormatSpecification (co.cask.cdap.api.data.format.FormatSpecification)2 ViewSpecification (co.cask.cdap.proto.ViewSpecification)2 StreamId (co.cask.cdap.proto.id.StreamId)2 StreamViewId (co.cask.cdap.proto.id.StreamViewId)2 Test (org.junit.Test)2 Schema (co.cask.cdap.api.data.schema.Schema)1 RowMaker (co.cask.cdap.cli.util.RowMaker)1 Table (co.cask.cdap.cli.util.table.Table)1 ExploreExecutionResult (co.cask.cdap.explore.client.ExploreExecutionResult)1 QueryResult (co.cask.cdap.proto.QueryResult)1 NamespaceId (co.cask.cdap.proto.id.NamespaceId)1 HttpResponse (co.cask.common.http.HttpResponse)1 ImmutableList (com.google.common.collect.ImmutableList)1 TypeToken (com.google.common.reflect.TypeToken)1 URL (java.net.URL)1 List (java.util.List)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1