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