Search in sources :

Example 21 with NamespaceId

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

the class RemotePreferencesFetcherInternal method getPreferencesURI.

/**
 * Construct URI to fetch preferences depending on the type of supplied entity
 */
private String getPreferencesURI(EntityId entityId, boolean resolved) {
    String uri;
    switch(entityId.getEntityType()) {
        case INSTANCE:
            uri = "preferences";
            break;
        case NAMESPACE:
            NamespaceId namespaceId = (NamespaceId) entityId;
            uri = String.format("namespaces/%s/preferences", namespaceId.getNamespace());
            break;
        case APPLICATION:
            ApplicationId appId = (ApplicationId) entityId;
            uri = String.format("namespaces/%s/apps/%s/preferences", appId.getNamespace(), appId.getApplication());
            break;
        case PROGRAM:
            ProgramId programId = (ProgramId) entityId;
            uri = String.format("namespaces/%s/apps/%s/%s/%s/preferences", programId.getNamespace(), programId.getApplication(), programId.getType().getCategoryName(), programId.getProgram());
            break;
        default:
            throw new UnsupportedOperationException(String.format("Preferences cannot be used on this entity type: %s", entityId.getEntityType()));
    }
    if (resolved) {
        uri += "?resolved=true";
    }
    return uri;
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 22 with NamespaceId

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

the class LineageClient method getLineage.

private <T> T getLineage(NamespacedEntityId namespacedId, String path, Class<T> type) throws IOException, UnauthenticatedException, NotFoundException, BadRequestException, UnauthorizedException {
    URL lineageURL = config.resolveNamespacedURLV3(new NamespaceId(namespacedId.getNamespace()), path);
    HttpResponse response = restClient.execute(HttpRequest.get(lineageURL).build(), config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
        throw new BadRequestException(response.getResponseBodyAsString());
    }
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(response.getResponseBodyAsString());
    }
    return GSON.fromJson(response.getResponseBodyAsString(), type);
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) BadRequestException(io.cdap.cdap.common.BadRequestException) NotFoundException(io.cdap.cdap.common.NotFoundException) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) URL(java.net.URL)

Example 23 with NamespaceId

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

the class WorkflowClient method getWorkflowLocalDatasetURL.

private URL getWorkflowLocalDatasetURL(ProgramRunId workflowRunId) throws MalformedURLException {
    String path = String.format("apps/%s/workflows/%s/runs/%s/localdatasets", workflowRunId.getApplication(), workflowRunId.getProgram(), workflowRunId.getRun());
    NamespaceId namespaceId = workflowRunId.getNamespaceId();
    return config.resolveNamespacedURLV3(namespaceId, path);
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId)

Example 24 with NamespaceId

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

the class HiveExploreServiceTestRun method testCustomDatabaseAndTableName.

@Test
public void testCustomDatabaseAndTableName() throws Exception {
    NamespaceId namespaceId = new NamespaceId("abc");
    DatasetId datasetId = NAMESPACE_ID.dataset("xyzTable");
    createNamespace(namespaceId);
    try {
        testTableInfo(datasetId, null, null);
        testTableInfo(datasetId, null, "xyz");
        testTableInfo(datasetId, "cdap_abc", null);
        testTableInfo(datasetId, "cdap_abc", "xyz");
    } finally {
        deleteNamespace(namespaceId);
    }
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) DatasetId(io.cdap.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 25 with NamespaceId

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

the class HiveExploreServiceTestRun method testQueriesList.

@Test
public void testQueriesList() throws Exception {
    ListenableFuture<ExploreExecutionResult> future;
    ExploreExecutionResult results;
    List<QueryInfo> queries;
    // Use different namespaces than the other tests so that when its run in a suite there isn't a chance of
    // stray queries polluting this test
    NamespaceId testNamespace1 = new NamespaceId("test1");
    NamespaceId testNamespace2 = new NamespaceId("test2");
    NamespaceMeta testNamespace1Meta = new NamespaceMeta.Builder().setName(testNamespace1).build();
    namespaceAdmin.create(testNamespace1Meta);
    NamespaceMeta testNamespace2Meta = new NamespaceMeta.Builder().setName(testNamespace2).build();
    namespaceAdmin.create(testNamespace2Meta);
    exploreClient.addNamespace(testNamespace1Meta).get();
    exploreClient.addNamespace(testNamespace2Meta).get();
    exploreClient.submit(testNamespace1, "create table my_table (first INT, second STRING)").get();
    future = exploreClient.submit(testNamespace1, "show tables");
    future.get();
    future = exploreClient.submit(testNamespace2, "show tables");
    future.get();
    future = exploreClient.submit(testNamespace1, "select * from my_table");
    results = future.get();
    queries = exploreService.getQueries(testNamespace1);
    Assert.assertEquals(2, queries.size());
    Assert.assertEquals("select * from my_table", queries.get(0).getStatement());
    Assert.assertEquals("FINISHED", queries.get(0).getStatus().toString());
    Assert.assertTrue(queries.get(0).isHasResults());
    Assert.assertTrue(queries.get(0).isActive());
    Assert.assertEquals("show tables", queries.get(1).getStatement());
    Assert.assertEquals("FINISHED", queries.get(1).getStatus().toString());
    Assert.assertTrue(queries.get(1).isHasResults());
    Assert.assertTrue(queries.get(1).isActive());
    // Make the last query inactive
    while (results.hasNext()) {
        results.next();
    }
    queries = exploreService.getQueries(testNamespace1);
    Assert.assertEquals(2, queries.size());
    Assert.assertEquals("select * from my_table", queries.get(0).getStatement());
    Assert.assertEquals("FINISHED", queries.get(0).getStatus().toString());
    Assert.assertTrue(queries.get(0).isHasResults());
    Assert.assertFalse(queries.get(0).isActive());
    Assert.assertEquals("show tables", queries.get(1).getStatement());
    Assert.assertEquals("FINISHED", queries.get(1).getStatus().toString());
    Assert.assertTrue(queries.get(1).isHasResults());
    Assert.assertTrue(queries.get(1).isActive());
    // Close last query
    results.close();
    queries = exploreService.getQueries(testNamespace1);
    Assert.assertEquals(1, queries.size());
    Assert.assertEquals("show tables", queries.get(0).getStatement());
    queries = exploreService.getQueries(testNamespace2);
    Assert.assertEquals(1, queries.size());
    Assert.assertEquals("show tables", queries.get(0).getStatement());
    Assert.assertEquals("FINISHED", queries.get(0).getStatus().toString());
    Assert.assertTrue(queries.get(0).isHasResults());
    Assert.assertTrue(queries.get(0).isActive());
    // Make sure queries are reverse ordered by timestamp
    exploreClient.submit(testNamespace1, "show tables").get();
    exploreClient.submit(testNamespace1, "show tables").get();
    exploreClient.submit(testNamespace1, "show tables").get();
    exploreClient.submit(testNamespace1, "show tables").get();
    queries = exploreService.getQueries(testNamespace1);
    List<Long> timestamps = Lists.newArrayList();
    Assert.assertEquals(5, queries.size());
    for (QueryInfo queryInfo : queries) {
        Assert.assertNotNull(queryInfo.getStatement());
        Assert.assertNotNull(queryInfo.getQueryHandle());
        Assert.assertTrue(queryInfo.isActive());
        Assert.assertEquals("FINISHED", queryInfo.getStatus().toString());
        Assert.assertEquals("show tables", queryInfo.getStatement());
        timestamps.add(queryInfo.getTimestamp());
    }
    // verify the ordering
    Assert.assertTrue(Ordering.natural().reverse().isOrdered(timestamps));
    exploreClient.submit(testNamespace1, "drop table if exists my_table").get();
    exploreClient.removeNamespace(testNamespace1).get();
    exploreClient.removeNamespace(testNamespace2).get();
}
Also used : NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) QueryInfo(io.cdap.cdap.proto.QueryInfo) ExploreExecutionResult(io.cdap.cdap.explore.client.ExploreExecutionResult) 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