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();
}
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);
}
}
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);
}
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();
}
}
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));
}
Aggregations