Search in sources :

Example 1 with StreamDetail

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);
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) StreamDetail(co.cask.cdap.proto.StreamDetail) ArtifactClient(co.cask.cdap.client.ArtifactClient) DatasetSpecificationSummary(co.cask.cdap.proto.DatasetSpecificationSummary) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord)

Example 2 with StreamDetail

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));
}
Also used : StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) StreamDetail(co.cask.cdap.proto.StreamDetail) ArrayList(java.util.ArrayList) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with StreamDetail

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());
}
Also used : DatasetDetail(co.cask.cdap.proto.DatasetDetail) StreamDetail(co.cask.cdap.proto.StreamDetail) EntityId(co.cask.cdap.proto.id.EntityId) ApplicationDetail(co.cask.cdap.proto.ApplicationDetail) ProgramRecord(co.cask.cdap.proto.ProgramRecord) Principal(co.cask.cdap.proto.security.Principal)

Example 4 with StreamDetail

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);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) StreamDetail(co.cask.cdap.proto.StreamDetail)

Example 5 with StreamDetail

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
    }
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) StreamDetail(co.cask.cdap.proto.StreamDetail) NamespaceId(co.cask.cdap.proto.id.NamespaceId) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) Test(org.junit.Test)

Aggregations

StreamDetail (co.cask.cdap.proto.StreamDetail)7 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)2 NamespaceId (co.cask.cdap.proto.id.NamespaceId)2 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)1 StreamSpecification (co.cask.cdap.api.data.stream.StreamSpecification)1 RowMaker (co.cask.cdap.cli.util.RowMaker)1 Table (co.cask.cdap.cli.util.table.Table)1 ArtifactClient (co.cask.cdap.client.ArtifactClient)1 ApplicationDetail (co.cask.cdap.proto.ApplicationDetail)1 ApplicationRecord (co.cask.cdap.proto.ApplicationRecord)1 DatasetDetail (co.cask.cdap.proto.DatasetDetail)1 DatasetSpecificationSummary (co.cask.cdap.proto.DatasetSpecificationSummary)1 ProgramRecord (co.cask.cdap.proto.ProgramRecord)1 EntityId (co.cask.cdap.proto.id.EntityId)1 StreamId (co.cask.cdap.proto.id.StreamId)1 Principal (co.cask.cdap.proto.security.Principal)1 HttpRequest (co.cask.common.http.HttpRequest)1 HttpResponse (co.cask.common.http.HttpResponse)1 TypeToken (com.google.common.reflect.TypeToken)1 URL (java.net.URL)1