use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method testSearchTargetType.
@Test
public void testSearchTargetType() throws Exception {
NamespaceId namespace = Ids.namespace("testSearchTargetType");
namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
appClient.deploy(namespace, createAppJarFile(AllProgramsApp.class));
// Add metadata to app
Set<String> tags = ImmutableSet.of("utag1", "utag2");
ApplicationId appId = Ids.namespace(namespace.getNamespace()).app(AllProgramsApp.NAME);
addTags(appId, tags);
// Add metadata to stream
tags = ImmutableSet.of("utag11");
StreamId streamId = Ids.namespace(namespace.getNamespace()).stream(AllProgramsApp.STREAM_NAME);
addTags(streamId, tags);
// Add metadata to dataset
tags = ImmutableSet.of("utag21");
DatasetId datasetId = Ids.namespace(namespace.getNamespace()).dataset(AllProgramsApp.DATASET_NAME);
addTags(datasetId, tags);
// Search for single target type
Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(appId)), searchMetadata(namespace, "utag*", EntityTypeSimpleName.APP));
Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(datasetId)), searchMetadata(namespace, "utag*", EntityTypeSimpleName.DATASET));
// Search for multiple target types
Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(datasetId), new MetadataSearchResultRecord(streamId)), searchMetadata(namespace, "utag*", ImmutableSet.of(EntityTypeSimpleName.DATASET, EntityTypeSimpleName.STREAM)));
Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(datasetId), new MetadataSearchResultRecord(appId)), searchMetadata(namespace, "utag*", ImmutableSet.of(EntityTypeSimpleName.APP, EntityTypeSimpleName.DATASET)));
// Search for all target types
Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(datasetId), new MetadataSearchResultRecord(appId), new MetadataSearchResultRecord(streamId)), searchMetadata(namespace, "utag*", EntityTypeSimpleName.ALL));
Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(datasetId), new MetadataSearchResultRecord(appId), new MetadataSearchResultRecord(streamId)), searchMetadata(namespace, "utag*", ImmutableSet.of(EntityTypeSimpleName.DATASET, EntityTypeSimpleName.ALL)));
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method testSearchMetadataDelete.
@Test
public void testSearchMetadataDelete() throws Exception {
NamespaceId namespace = new NamespaceId("ns1");
namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
// Deploy app
appClient.deploy(namespace, createAppJarFile(WordCountApp.class, WordCountApp.class.getSimpleName(), "1.0"));
Set<String> tags = ImmutableSet.of("tag1", "tag2");
ArtifactId artifact = namespace.artifact("WordCountApp", "1.0");
ApplicationId app = namespace.app("WordCountApp");
ProgramId flow = app.flow("WordCountFlow");
ProgramId service = app.service("WordFrequencyService");
StreamId stream = namespace.stream("text");
DatasetId datasetInstance = namespace.dataset("mydataset");
StreamViewId view = stream.view("view");
streamViewClient.createOrUpdate(view, new ViewSpecification(new FormatSpecification("csv", null, null)));
// Add metadata
addTags(app, tags);
addTags(flow, tags);
addTags(stream, tags);
addTags(datasetInstance, tags);
addTags(view, tags);
// Assert metadata
Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(stream), new MetadataSearchResultRecord(view)), searchMetadata(namespace, "text"));
Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(datasetInstance)), searchMetadata(namespace, "mydataset"));
Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(app), new MetadataSearchResultRecord(flow), new MetadataSearchResultRecord(artifact), new MetadataSearchResultRecord(service)), searchMetadata(namespace, "word*"));
Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(app), new MetadataSearchResultRecord(flow), new MetadataSearchResultRecord(stream), new MetadataSearchResultRecord(datasetInstance), new MetadataSearchResultRecord(view)), searchMetadata(namespace, "tag1"));
// Delete entities
appClient.delete(app);
streamViewClient.delete(view);
streamClient.delete(stream);
datasetClient.delete(datasetInstance);
artifactClient.delete(artifact);
// Assert no metadata
Assert.assertEquals(ImmutableSet.of(), searchMetadata(namespace, "text"));
Assert.assertEquals(ImmutableSet.of(), searchMetadata(namespace, "mydataset"));
Assert.assertEquals(ImmutableSet.of(), searchMetadata(namespace, "word*"));
Assert.assertEquals(ImmutableSet.of(), searchMetadata(namespace, "tag1"));
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class InstanceURIParser method parse.
public CLIConnectionConfig parse(String uriString) {
if (!uriString.contains("://")) {
uriString = DEFAULT_PROTOCOL + "://" + uriString;
}
URI uri = URI.create(uriString);
NamespaceId namespace = (uri.getPath() == null || uri.getPath().isEmpty() || "/".equals(uri.getPath())) ? NamespaceId.DEFAULT : new NamespaceId(uri.getPath().substring(1));
String hostname = uri.getHost();
boolean sslEnabled = "https".equals(uri.getScheme());
int port = uri.getPort();
if (port == -1) {
port = sslEnabled ? cConf.getInt(Constants.Router.ROUTER_SSL_PORT) : cConf.getInt(Constants.Router.ROUTER_PORT);
}
ConnectionConfig config = ConnectionConfig.builder().setHostname(hostname).setPort(port).setSSLEnabled(sslEnabled).build();
return new CLIConnectionConfig(config, namespace, null);
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class PreferencesClientTestRun method testInvalidProgram.
@Test(expected = ProgramNotFoundException.class)
public void testInvalidProgram() throws Exception {
ApplicationId someapp = new NamespaceId("somespace").app("someapp");
client.deleteProgramPreferences(someapp.flow("myflow"));
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class PreferencesClientTestRun method testInvalidApplication.
@Test(expected = NotFoundException.class)
public void testInvalidApplication() throws Exception {
ApplicationId someapp = new NamespaceId("somespace").app("someapp");
client.getApplicationPreferences(someapp, true);
}
Aggregations