Search in sources :

Example 21 with StreamViewId

use of co.cask.cdap.proto.id.StreamViewId 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, detail, ViewDetail.class, GSON);
}
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)

Example 22 with StreamViewId

use of co.cask.cdap.proto.id.StreamViewId in project cdap by caskdata.

the class StreamViewHttpHandler method list.

@GET
@Path("/streams/{stream}/views")
public void list(HttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("stream") String stream) throws Exception {
    StreamId streamId = new StreamId(namespace, stream);
    Collection<String> list = Collections2.transform(admin.listViews(streamId), new Function<StreamViewId, String>() {

        @Override
        public String apply(StreamViewId input) {
            return input.getEntityName();
        }
    });
    responder.sendJson(HttpResponseStatus.OK, list);
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) StreamViewId(co.cask.cdap.proto.id.StreamViewId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 23 with StreamViewId

use of co.cask.cdap.proto.id.StreamViewId in project cdap by caskdata.

the class StreamClientTestRun method testStreamDeleteAfterCreatingView.

@Test
public void testStreamDeleteAfterCreatingView() throws Exception {
    StreamId testStream = NamespaceId.DEFAULT.stream("testStream");
    streamClient.create(testStream);
    // should throw StreamNotFoundException if the stream has not been successfully created in the previous step
    streamClient.getConfig(testStream);
    StreamViewClient streamViewClient = new StreamViewClient(clientConfig);
    StreamViewId testView = testStream.view("testView");
    ViewSpecification testViewSpec = new ViewSpecification(new FormatSpecification("csv", null, null));
    Assert.assertTrue(streamViewClient.createOrUpdate(testView, testViewSpec));
    // test stream delete
    streamClient.delete(testStream);
    // recreate the stream and the view
    streamClient.create(testStream);
    // should throw StreamNotFoundException if the stream has not been successfully created in the previous step
    streamClient.getConfig(testStream);
    Assert.assertTrue(streamViewClient.createOrUpdate(testView, testViewSpec));
    // test that namespace deletion succeeds
    namespaceClient.delete(NamespaceId.DEFAULT);
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) FormatSpecification(co.cask.cdap.api.data.format.FormatSpecification) ViewSpecification(co.cask.cdap.proto.ViewSpecification) StreamViewId(co.cask.cdap.proto.id.StreamViewId) Test(org.junit.Test)

Example 24 with StreamViewId

use of co.cask.cdap.proto.id.StreamViewId in project cdap by caskdata.

the class EntityIdKeyHelper method addTargetIdToKey.

public static void addTargetIdToKey(MDSKey.Builder builder, NamespacedEntityId namespacedEntityId) {
    String type = getTargetType(namespacedEntityId);
    if (type.equals(TYPE_MAP.get(NamespaceId.class))) {
        NamespaceId namespaceId = (NamespaceId) namespacedEntityId;
        builder.add(namespaceId.getNamespace());
    } else if (type.equals(TYPE_MAP.get(ProgramId.class))) {
        ProgramId program = (ProgramId) namespacedEntityId;
        String namespaceId = program.getNamespace();
        String appId = program.getApplication();
        String programType = program.getType().name();
        String programId = program.getProgram();
        builder.add(namespaceId);
        builder.add(appId);
        builder.add(programType);
        builder.add(programId);
    } else if (type.equals(TYPE_MAP.get(ApplicationId.class))) {
        ApplicationId application = (ApplicationId) namespacedEntityId;
        String namespaceId = application.getNamespace();
        String appId = application.getApplication();
        builder.add(namespaceId);
        builder.add(appId);
    } else if (type.equals(TYPE_MAP.get(DatasetId.class))) {
        DatasetId datasetInstance = (DatasetId) namespacedEntityId;
        String namespaceId = datasetInstance.getNamespace();
        String datasetId = datasetInstance.getDataset();
        builder.add(namespaceId);
        builder.add(datasetId);
    } else if (type.equals(TYPE_MAP.get(StreamId.class))) {
        StreamId stream = (StreamId) namespacedEntityId;
        String namespaceId = stream.getNamespace();
        String streamId = stream.getStream();
        builder.add(namespaceId);
        builder.add(streamId);
    } else if (type.equals(TYPE_MAP.get(StreamViewId.class))) {
        StreamViewId view = (StreamViewId) namespacedEntityId;
        String namespaceId = view.getNamespace();
        String streamId = view.getStream();
        String viewId = view.getView();
        builder.add(namespaceId);
        builder.add(streamId);
        builder.add(viewId);
    } else if (type.equals(TYPE_MAP.get(ArtifactId.class))) {
        ArtifactId artifactId = (ArtifactId) namespacedEntityId;
        String namespaceId = artifactId.getNamespace();
        String name = artifactId.getArtifact();
        String version = artifactId.getVersion();
        builder.add(namespaceId);
        builder.add(name);
        builder.add(version);
    } else {
        throw new IllegalArgumentException("Illegal Type " + type + " of metadata source.");
    }
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ProgramId(co.cask.cdap.proto.id.ProgramId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) DatasetId(co.cask.cdap.proto.id.DatasetId) StreamViewId(co.cask.cdap.proto.id.StreamViewId)

Example 25 with StreamViewId

use of co.cask.cdap.proto.id.StreamViewId in project cdap by caskdata.

the class CreateOrUpdateStreamViewCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    StreamId streamId = cliConfig.getCurrentNamespace().stream(arguments.get(ArgumentName.STREAM.toString()));
    StreamViewId viewId = streamId.view(arguments.get(ArgumentName.VIEW.toString()));
    String formatName = arguments.get(ArgumentName.FORMAT.toString());
    Schema schema = getSchema(arguments);
    Map<String, String> settings = Collections.emptyMap();
    if (arguments.hasArgument(ArgumentName.SETTINGS.toString())) {
        settings = ArgumentParser.parseMap(arguments.get(ArgumentName.SETTINGS.toString()), ArgumentName.SETTINGS.toString());
    }
    FormatSpecification formatSpecification = new FormatSpecification(formatName, schema, settings);
    ViewSpecification viewSpecification = new ViewSpecification(formatSpecification);
    boolean created = client.createOrUpdate(viewId, viewSpecification);
    if (created) {
        output.printf("Successfully created stream-view '%s'\n", viewId.getEntityName());
    } else {
        output.printf("Successfully updated stream-view '%s'\n", viewId.getEntityName());
    }
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) Schema(co.cask.cdap.api.data.schema.Schema) FormatSpecification(co.cask.cdap.api.data.format.FormatSpecification) ViewSpecification(co.cask.cdap.proto.ViewSpecification) StreamViewId(co.cask.cdap.proto.id.StreamViewId)

Aggregations

StreamViewId (co.cask.cdap.proto.id.StreamViewId)32 StreamId (co.cask.cdap.proto.id.StreamId)16 Path (javax.ws.rs.Path)14 ViewSpecification (co.cask.cdap.proto.ViewSpecification)12 FormatSpecification (co.cask.cdap.api.data.format.FormatSpecification)11 DatasetId (co.cask.cdap.proto.id.DatasetId)9 Test (org.junit.Test)9 NamespaceId (co.cask.cdap.proto.id.NamespaceId)7 ApplicationId (co.cask.cdap.proto.id.ApplicationId)6 DELETE (javax.ws.rs.DELETE)6 ArtifactId (co.cask.cdap.proto.id.ArtifactId)5 ProgramId (co.cask.cdap.proto.id.ProgramId)5 MetadataSearchResultRecord (co.cask.cdap.proto.metadata.MetadataSearchResultRecord)5 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)4 GET (javax.ws.rs.GET)4 Schema (co.cask.cdap.api.data.schema.Schema)3 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)3 WordCountApp (co.cask.cdap.WordCountApp)2 NotFoundException (co.cask.cdap.common.NotFoundException)2 DatasetInstanceConfiguration (co.cask.cdap.proto.DatasetInstanceConfiguration)2