use of co.cask.cdap.proto.StreamDetail in project cdap by caskdata.
the class IntegrationTestBase method doClear.
private void doClear(NamespaceId namespace, boolean deleteNamespace) throws Exception {
// stop all programs in the namespace
getProgramClient().stopAll(namespace);
if (deleteNamespace) {
getNamespaceClient().delete(namespace);
return;
}
// delete all apps in the namespace
for (ApplicationRecord app : getApplicationClient().list(namespace)) {
getApplicationClient().delete(namespace.app(app.getName(), app.getAppVersion()));
}
// delete all streams
for (StreamDetail streamDetail : getStreamClient().list(namespace)) {
getStreamClient().delete(namespace.stream(streamDetail.getName()));
}
// delete all dataset instances
for (DatasetSpecificationSummary datasetSpecSummary : getDatasetClient().list(namespace)) {
getDatasetClient().delete(namespace.dataset(datasetSpecSummary.getName()));
}
ArtifactClient artifactClient = new ArtifactClient(getClientConfig(), getRestClient());
for (ArtifactSummary artifactSummary : artifactClient.list(namespace, ArtifactScope.USER)) {
artifactClient.delete(namespace.artifact(artifactSummary.getName(), artifactSummary.getVersion()));
}
assertIsClear(namespace);
}
use of co.cask.cdap.proto.StreamDetail in project cdap by caskdata.
the class StreamHandler method listStreams.
@GET
@Path("/")
public void listStreams(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
// Check for namespace existence. Throws NotFoundException if namespace doesn't exist
namespaceQueryAdmin.get(new NamespaceId(namespaceId));
List<StreamSpecification> specifications = streamAdmin.listStreams(new NamespaceId(namespaceId));
List<StreamDetail> streamDetails = new ArrayList<>(specifications.size());
for (StreamSpecification specification : specifications) {
streamDetails.add(new StreamDetail(specification.getName()));
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(streamDetails));
}
use of co.cask.cdap.proto.StreamDetail in project cdap by caskdata.
the class ApplicationLifecycleService method filterApplicationDetail.
/**
* Filter the {@link ApplicationDetail} by only returning the visible entities
*/
private ApplicationDetail filterApplicationDetail(final ApplicationId appId, ApplicationDetail applicationDetail) throws Exception {
Principal principal = authenticationContext.getPrincipal();
List<ProgramRecord> filteredPrograms = AuthorizationUtil.isVisible(applicationDetail.getPrograms(), authorizationEnforcer, principal, new Function<ProgramRecord, EntityId>() {
@Override
public EntityId apply(ProgramRecord input) {
return appId.program(input.getType(), input.getName());
}
}, null);
List<StreamDetail> filteredStreams = AuthorizationUtil.isVisible(applicationDetail.getStreams(), authorizationEnforcer, principal, new Function<StreamDetail, EntityId>() {
@Override
public EntityId apply(StreamDetail input) {
return appId.getNamespaceId().stream(input.getName());
}
}, null);
List<DatasetDetail> filteredDatasets = AuthorizationUtil.isVisible(applicationDetail.getDatasets(), authorizationEnforcer, principal, new Function<DatasetDetail, EntityId>() {
@Override
public EntityId apply(DatasetDetail input) {
return appId.getNamespaceId().dataset(input.getName());
}
}, null);
return new ApplicationDetail(applicationDetail.getName(), applicationDetail.getAppVersion(), applicationDetail.getDescription(), applicationDetail.getConfiguration(), filteredStreams, filteredDatasets, filteredPrograms, applicationDetail.getPlugins(), applicationDetail.getArtifact(), applicationDetail.getOwnerPrincipal());
}
use of co.cask.cdap.proto.StreamDetail in project cdap by caskdata.
the class ListStreamsCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
Table table = Table.builder().setHeader("name").setRows(streamClient.list(cliConfig.getCurrentNamespace()), new RowMaker<StreamDetail>() {
@Override
public List<?> makeRow(StreamDetail object) {
return Lists.newArrayList(object.getName());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of co.cask.cdap.proto.StreamDetail in project cdap by caskdata.
the class StreamHandlerTest method testListStreams.
@Test
public void testListStreams() throws Exception {
List<StreamDetail> specs = listStreams(NamespaceId.DEFAULT);
Assert.assertTrue(specs.isEmpty());
StreamId s1 = NamespaceId.DEFAULT.stream("stream1");
StreamId s2 = NamespaceId.DEFAULT.stream("stream2");
createStream(s1);
specs = listStreams(NamespaceId.DEFAULT);
Assert.assertEquals(1, specs.size());
StreamDetail specification = specs.get(0);
Assert.assertEquals(s1.getStream(), specification.getName());
createStream(s2);
specs = listStreams(NamespaceId.DEFAULT);
Assert.assertEquals(2, specs.size());
try {
listStreams(new NamespaceId("notfound"));
Assert.fail("Should have thrown NamespaceNotFoundException");
} catch (NamespaceNotFoundException ex) {
// expected
}
}
Aggregations