Search in sources :

Example 16 with NamespaceId

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)));
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) MetadataSearchResultRecord(co.cask.cdap.proto.metadata.MetadataSearchResultRecord) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) AllProgramsApp(co.cask.cdap.client.app.AllProgramsApp) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 17 with NamespaceId

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"));
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) FormatSpecification(co.cask.cdap.api.data.format.FormatSpecification) ViewSpecification(co.cask.cdap.proto.ViewSpecification) ProgramId(co.cask.cdap.proto.id.ProgramId) DatasetId(co.cask.cdap.proto.id.DatasetId) MetadataSearchResultRecord(co.cask.cdap.proto.metadata.MetadataSearchResultRecord) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) WordCountApp(co.cask.cdap.WordCountApp) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) StreamViewId(co.cask.cdap.proto.id.StreamViewId) Test(org.junit.Test)

Example 18 with NamespaceId

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);
}
Also used : CLIConnectionConfig(co.cask.cdap.cli.CLIConnectionConfig) NamespaceId(co.cask.cdap.proto.id.NamespaceId) URI(java.net.URI) ConnectionConfig(co.cask.cdap.client.config.ConnectionConfig) CLIConnectionConfig(co.cask.cdap.cli.CLIConnectionConfig)

Example 19 with NamespaceId

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"));
}
Also used : NamespaceId(co.cask.cdap.proto.id.NamespaceId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 20 with NamespaceId

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

Aggregations

NamespaceId (co.cask.cdap.proto.id.NamespaceId)234 Test (org.junit.Test)99 Path (javax.ws.rs.Path)47 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)43 ApplicationId (co.cask.cdap.proto.id.ApplicationId)35 IOException (java.io.IOException)34 StreamId (co.cask.cdap.proto.id.StreamId)30 DatasetId (co.cask.cdap.proto.id.DatasetId)27 TableId (co.cask.cdap.data2.util.TableId)26 Id (co.cask.cdap.proto.Id)24 ProgramId (co.cask.cdap.proto.id.ProgramId)24 NotFoundException (co.cask.cdap.common.NotFoundException)22 ArtifactId (co.cask.cdap.proto.id.ArtifactId)21 BadRequestException (co.cask.cdap.common.BadRequestException)20 TopicId (co.cask.cdap.proto.id.TopicId)19 GET (javax.ws.rs.GET)18 Location (org.apache.twill.filesystem.Location)18 ArrayList (java.util.ArrayList)15 TopicMetadata (co.cask.cdap.messaging.TopicMetadata)13 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)12