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