use of co.cask.cdap.proto.ViewSpecification 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.ViewSpecification in project cdap by caskdata.
the class ViewAdmin method delete.
public void delete(StreamViewId viewId) throws Exception {
ViewSpecification spec = store.get(viewId);
explore.disableExploreStream(viewId.getParent(), spec.getTableName());
store.delete(viewId);
metadataStore.removeMetadata(viewId);
}
use of co.cask.cdap.proto.ViewSpecification in project cdap by caskdata.
the class StreamViewHttpHandler method createOrUpdate.
@PUT
@Path("/streams/{stream}/views/{view}")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void createOrUpdate(HttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("stream") String stream, @PathParam("view") String view) throws Exception {
StreamViewId viewId;
try {
viewId = new StreamViewId(namespace, stream, view);
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
}
try (Reader reader = new InputStreamReader(new ChannelBufferInputStream(request.getContent()))) {
ViewSpecification spec = GSON.fromJson(reader, ViewSpecification.class);
if (spec == null) {
throw new BadRequestException("Missing ViewSpecification in request body");
}
boolean created = admin.createOrUpdateView(viewId, spec);
responder.sendStatus(created ? HttpResponseStatus.CREATED : HttpResponseStatus.OK);
} catch (JsonSyntaxException e) {
responder.sendString(HttpResponseStatus.BAD_REQUEST, "Couldn't decode body as view config JSON");
} catch (IOException e) {
LOG.warn("Error closing InputStreamReader", e);
}
}
use of co.cask.cdap.proto.ViewSpecification in project cdap by caskdata.
the class InMemoryViewStore method delete.
@Override
public void delete(StreamViewId viewId) throws NotFoundException {
ViewSpecification removed;
Lock lock = viewsLock.writeLock();
lock.lock();
try {
removed = views.remove(viewId, viewId.getParent());
} finally {
lock.unlock();
}
if (removed == null) {
throw new NotFoundException(viewId);
}
}
use of co.cask.cdap.proto.ViewSpecification in project cdap by caskdata.
the class EntityExistenceTest method setup.
@BeforeClass
public static void setup() throws Exception {
CConfiguration cConf = CConfiguration.create();
cConf.set(Constants.INSTANCE_NAME, EXISTS);
Injector injector = AppFabricTestHelper.getInjector(cConf);
NamespaceStore nsStore = injector.getInstance(NamespaceStore.class);
ArtifactRepository artifactRepository = injector.getInstance(ArtifactRepository.class);
cConf = injector.getInstance(CConfiguration.class);
nsStore.create(new NamespaceMeta.Builder().setName(EXISTS).build());
existenceVerifier = injector.getInstance(EntityExistenceVerifier.class);
LocalLocationFactory lf = new LocalLocationFactory(TEMPORARY_FOLDER.newFolder());
File artifactFile = new File(AppJarHelper.createDeploymentJar(lf, AllProgramsApp.class).toURI());
artifactRepository.addArtifact(ARTIFACT.toId(), artifactFile);
AppFabricTestHelper.deployApplication(NAMESPACE.toId(), AllProgramsApp.class, null, cConf);
StreamAdmin streamAdmin = injector.getInstance(StreamAdmin.class);
streamAdmin.createOrUpdateView(VIEW, new ViewSpecification(new FormatSpecification("csv", null)));
}
Aggregations