Search in sources :

Example 71 with NamespaceId

use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class MetadataHttpHandlerTestRun method testInvalidParams.

@Test
public void testInvalidParams() throws Exception {
    NamespaceId namespace = new NamespaceId("testInvalidParams");
    namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
    try {
        Set<String> targets = Collections.emptySet();
        searchMetadata(namespace, "text", targets, MetadataConstants.CREATION_TIME_KEY + " desc");
        Assert.fail("Expected not to be able to specify 'query' and 'sort' parameters.");
    } catch (BadRequestException expected) {
    // expected
    }
}
Also used : NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) BadRequestException(io.cdap.cdap.common.BadRequestException) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 72 with NamespaceId

use of io.cdap.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(AllProgramsApp.class, AllProgramsApp.class.getSimpleName(), "1.0"));
    ArtifactId artifact = namespace.artifact(AllProgramsApp.class.getSimpleName(), "1.0");
    ApplicationId app = namespace.app(AllProgramsApp.NAME);
    ProgramId service = app.service(AllProgramsApp.NoOpService.NAME);
    DatasetId datasetInstance = namespace.dataset(AllProgramsApp.DATASET_NAME);
    // wait for metadata to be processed
    Tasks.waitFor(false, () -> getProperties(app, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
    Tasks.waitFor(false, () -> getProperties(service, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
    Tasks.waitFor(false, () -> getProperties(datasetInstance, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
    Set<String> tags = ImmutableSet.of("tag1", "tag2");
    // Add metadata
    addTags(app, tags);
    addTags(datasetInstance, tags);
    // Assert metadata
    assertSearch(searchMetadata(namespace, AllProgramsApp.DATASET_NAME), datasetInstance);
    assertSearch(searchMetadata(namespace, "all*"), app, artifact);
    assertSearch(searchMetadata(namespace, "tag1"), app, datasetInstance);
    // Delete entities
    appClient.delete(app);
    datasetClient.delete(datasetInstance);
    artifactClient.delete(artifact);
    // Assert no metadata
    waitForSearch(() -> searchMetadata(namespace, AllProgramsApp.DATASET_NAME));
    waitForSearch(() -> searchMetadata(namespace, "all*"));
    waitForSearch(() -> searchMetadata(namespace, "tag1"));
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) AllProgramsApp(io.cdap.cdap.client.app.AllProgramsApp) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) DatasetId(io.cdap.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 73 with NamespaceId

use of io.cdap.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(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 74 with NamespaceId

use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class PreferencesClientTestRun method testPreferences.

@Test
public void testPreferences() throws Exception {
    NamespaceId invalidNamespace = new NamespaceId("invalid");
    namespaceClient.create(new NamespaceMeta.Builder().setName(invalidNamespace).build());
    Map<String, String> propMap = client.getInstancePreferences();
    Assert.assertEquals(ImmutableMap.<String, String>of(), propMap);
    propMap.put("k1", "instance");
    client.setInstancePreferences(propMap);
    Assert.assertEquals(propMap, client.getInstancePreferences());
    File jarFile = createAppJarFile(FakeApp.class);
    appClient.deploy(NamespaceId.DEFAULT, jarFile);
    try {
        propMap.put("k1", "namespace");
        client.setNamespacePreferences(NamespaceId.DEFAULT, propMap);
        Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
        Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, false));
        Assert.assertTrue(client.getNamespacePreferences(invalidNamespace, false).isEmpty());
        Assert.assertEquals("instance", client.getNamespacePreferences(invalidNamespace, true).get("k1"));
        client.deleteNamespacePreferences(NamespaceId.DEFAULT);
        propMap.put("k1", "instance");
        Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
        Assert.assertEquals(ImmutableMap.<String, String>of(), client.getNamespacePreferences(NamespaceId.DEFAULT, false));
        propMap.put("k1", "namespace");
        client.setNamespacePreferences(NamespaceId.DEFAULT, propMap);
        Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
        Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, false));
        propMap.put("k1", "application");
        client.setApplicationPreferences(FAKE_APP_ID, propMap);
        Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, true));
        Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, false));
        propMap.put("k1", "program");
        ServiceId service = FAKE_APP_ID.service(FakeApp.SERVICES.get(0));
        client.setProgramPreferences(service, propMap);
        Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
        Assert.assertEquals(propMap, client.getProgramPreferences(service, false));
        client.deleteProgramPreferences(service);
        propMap.put("k1", "application");
        Assert.assertTrue(client.getProgramPreferences(service, false).isEmpty());
        Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
        client.deleteApplicationPreferences(FAKE_APP_ID);
        propMap.put("k1", "namespace");
        Assert.assertTrue(client.getApplicationPreferences(FAKE_APP_ID, false).isEmpty());
        Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, true));
        Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
        client.deleteNamespacePreferences(NamespaceId.DEFAULT);
        propMap.put("k1", "instance");
        Assert.assertTrue(client.getNamespacePreferences(NamespaceId.DEFAULT, false).isEmpty());
        Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
        Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, true));
        Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
        client.deleteInstancePreferences();
        propMap.clear();
        Assert.assertEquals(propMap, client.getInstancePreferences());
        Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
        Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
        Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, true));
        Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
        // Test Deleting Application
        propMap.put("k1", "application");
        client.setApplicationPreferences(FAKE_APP_ID, propMap);
        Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, false));
        propMap.put("k1", "program");
        client.setProgramPreferences(service, propMap);
        Assert.assertEquals(propMap, client.getProgramPreferences(service, false));
        appClient.delete(FAKE_APP_ID);
        // deleting the app should have deleted the preferences that were stored. so deploy the app and check
        // if the preferences are empty. we need to deploy the app again since getting preferences of non-existent apps
        // is not allowed by the API.
        appClient.deploy(NamespaceId.DEFAULT, jarFile);
        propMap.clear();
        Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, false));
        Assert.assertEquals(propMap, client.getProgramPreferences(service, false));
    } finally {
        try {
            appClient.delete(FAKE_APP_ID);
        } catch (ApplicationNotFoundException e) {
        // ok if this happens, means its already deleted.
        }
        namespaceClient.delete(invalidNamespace);
    }
}
Also used : ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) File(java.io.File) ServiceId(io.cdap.cdap.proto.id.ServiceId) Test(org.junit.Test)

Example 75 with NamespaceId

use of io.cdap.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.worker("myworker"));
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Aggregations

NamespaceId (io.cdap.cdap.proto.id.NamespaceId)648 Test (org.junit.Test)292 Path (javax.ws.rs.Path)136 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)124 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)108 IOException (java.io.IOException)102 ProgramId (io.cdap.cdap.proto.id.ProgramId)86 GET (javax.ws.rs.GET)74 DatasetId (io.cdap.cdap.proto.id.DatasetId)68 ArrayList (java.util.ArrayList)64 BadRequestException (io.cdap.cdap.common.BadRequestException)60 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)58 Principal (io.cdap.cdap.proto.security.Principal)56 Set (java.util.Set)52 Id (io.cdap.cdap.common.id.Id)50 File (java.io.File)50 HashSet (java.util.HashSet)50 NotFoundException (io.cdap.cdap.common.NotFoundException)48 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)46 HashMap (java.util.HashMap)46