use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class DatasetTypeHandlerTest method testNotFound.
@Test
public void testNotFound() throws Exception {
NamespaceId nonExistent = new NamespaceId("nonExistent");
HttpResponse response = makeModulesRequest(nonExistent);
assertNamespaceNotFound(response, nonExistent);
response = makeTypesRequest(nonExistent);
assertNamespaceNotFound(response, nonExistent);
DatasetModuleId datasetModule = nonExistent.datasetModule("module");
response = makeModuleInfoRequest(datasetModule);
assertNamespaceNotFound(response, nonExistent);
DatasetTypeId datasetType = nonExistent.datasetType("type");
response = makeTypeInfoRequest(datasetType);
assertNamespaceNotFound(response, nonExistent);
response = deployModule(datasetModule, TestModule1.class);
assertNamespaceNotFound(response, nonExistent);
response = deleteModule(datasetModule);
assertNamespaceNotFound(response, nonExistent);
response = deleteModules(nonExistent);
assertNamespaceNotFound(response, nonExistent);
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class HBaseQueueDebugger method main.
public static void main(String[] args) throws Exception {
if (args.length >= 1 && args[0].equals("help")) {
System.out.println("Arguments: [<queue-uri> [consumer-flowlet]]");
System.out.println("queue-uri: queue:///<namespace>/<app>/<flow>/<flowlet>/<queue>");
System.out.println("consumer-flowlet: <flowlet>");
System.out.println("If queue-uri is not provided, scan all queues");
System.out.println("Example: queue:///default/PurchaseHistory/PurchaseFlow/reader/queue collector");
System.out.println();
System.out.println("System properties:");
System.out.println("-D" + PROP_SHOW_PROGRESS + "=true Show progress while scanning the queue table");
System.out.println("-D" + PROP_ROWS_CACHE + "=[num_of_rows] " + "Number of rows to pass to HBase Scan.setCaching() method");
System.exit(1);
}
// e.g. "queue:///default/PurchaseHistory/PurchaseFlow/reader/queue"
final QueueName queueName = args.length >= 1 ? QueueName.from(URI.create(args[0])) : null;
Long consumerGroupId = null;
if (args.length >= 2) {
Preconditions.checkNotNull(queueName);
String consumerFlowlet = args[1];
FlowId flowId = new FlowId(queueName.getFirstComponent(), queueName.getSecondComponent(), queueName.getThirdComponent());
consumerGroupId = FlowUtils.generateConsumerGroupId(flowId, consumerFlowlet);
}
final HBaseQueueDebugger debugger = createDebugger();
debugger.startAndWait();
// CDAP-9005 We need to create the NamespaceQueryAdmin without authorization enabled, but create the
// HBaseQueueDebugger with authorization enabled.
Injector injector = createInjector(true);
NoAuthService noAuthService = injector.getInstance(NoAuthService.class);
noAuthService.startAndWait();
NamespaceQueryAdmin namespaceQueryAdmin = noAuthService.getNamespaceQueryAdmin();
Impersonator impersonator = noAuthService.getImpersonator();
if (queueName != null) {
final Long finalConsumerGroupId = consumerGroupId;
impersonator.doAs(new NamespaceId(queueName.getFirstComponent()), new Callable<Void>() {
@Override
public Void call() throws Exception {
debugger.scanQueue(queueName, finalConsumerGroupId);
return null;
}
});
} else {
debugger.scanQueues(namespaceQueryAdmin.list());
}
noAuthService.stopAndWait();
debugger.stopAndWait();
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class HBaseQueueDebugger method scanQueues.
private void scanQueues(List<NamespaceMeta> namespaceMetas) throws Exception {
final QueueStatistics totalStats = new QueueStatistics();
for (NamespaceMeta namespaceMeta : namespaceMetas) {
final NamespaceId namespaceId = new NamespaceId(namespaceMeta.getName());
final Collection<ApplicationSpecification> apps = store.getAllApplications(namespaceId);
for (final ApplicationSpecification app : apps) {
ApplicationId appId = new ApplicationId(namespaceMeta.getName(), app.getName(), app.getAppVersion());
Collection<FlowSpecification> flows = app.getFlows().values();
for (final FlowSpecification flow : flows) {
final ProgramId flowId = appId.program(ProgramType.FLOW, flow.getName());
impersonator.doAs(flowId, new Callable<Void>() {
@Override
public Void call() throws Exception {
SimpleQueueSpecificationGenerator queueSpecGenerator = new SimpleQueueSpecificationGenerator(flowId.getParent());
Table<QueueSpecificationGenerator.Node, String, Set<QueueSpecification>> table = queueSpecGenerator.create(flow);
for (Table.Cell<QueueSpecificationGenerator.Node, String, Set<QueueSpecification>> cell : table.cellSet()) {
if (cell.getRowKey().getType() == FlowletConnection.Type.FLOWLET) {
for (QueueSpecification queue : cell.getValue()) {
QueueStatistics queueStats = scanQueue(queue.getQueueName(), null);
totalStats.add(queueStats);
}
}
}
return null;
}
});
}
}
}
System.out.printf("Total results for all queues: %s\n", totalStats.getReport(showTxTimestampOnly()));
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class IntegrationTestBaseTest method testDeployApplicationInNamespace.
@Test
public void testDeployApplicationInNamespace() throws Exception {
NamespaceId namespace = new NamespaceId("Test1");
NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(namespace).build();
getNamespaceClient().create(namespaceMeta);
ClientConfig clientConfig = new ClientConfig.Builder(getClientConfig()).build();
deployApplication(namespace, TestApplication.class);
// Check the default namespaces applications to see whether the application wasnt made in the default namespace
ClientConfig defaultClientConfig = new ClientConfig.Builder(getClientConfig()).build();
Assert.assertEquals(0, new ApplicationClient(defaultClientConfig).list(NamespaceId.DEFAULT).size());
ApplicationClient applicationClient = new ApplicationClient(clientConfig);
Assert.assertEquals(TestApplication.NAME, applicationClient.list(namespace).get(0).getName());
applicationClient.delete(namespace.app(TestApplication.NAME));
Assert.assertEquals(0, new ApplicationClient(clientConfig).list(namespace).size());
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class AuditMessageTest method testAccessMessage.
@Test
public void testAccessMessage() throws Exception {
String flowAccessJson = "{\"version\":1,\"time\":2000,\"entityId\":{\"namespace\":\"ns1\",\"stream\":\"stream1\"," + "\"entity\":\"STREAM\"},\"user\":\"user1\",\"type\":\"ACCESS\",\"payload\":{\"accessType\":\"WRITE\"," + "\"accessor\":{\"namespace\":\"ns1\",\"application\":\"app1\",\"version\":\"v1\",\"type\":\"Flow\"," + "\"program\":\"flow1\",\"run\":\"run1\",\"entity\":\"PROGRAM_RUN\"}}}";
AuditMessage flowAccess = new AuditMessage(2000L, new NamespaceId("ns1").stream("stream1"), "user1", AuditType.ACCESS, new AccessPayload(AccessType.WRITE, new NamespaceId("ns1").app("app1", "v1").flow("flow1").run("run1")));
Assert.assertEquals(jsonToMap(flowAccessJson), jsonToMap(GSON.toJson(flowAccess)));
Assert.assertEquals(flowAccess, GSON.fromJson(flowAccessJson, AuditMessage.class));
String exploreAccessJson = "{\"version\":1,\"time\":2500,\"entityId\":{\"namespace\":\"ns1\",\"dataset\":\"ds1\",\"entity\":\"DATASET\"}," + "\"user\":\"user1\",\"type\":\"ACCESS\",\"payload\":{\"accessType\":\"UNKNOWN\"," + "\"accessor\":{\"service\":\"explore\",\"entity\":\"SYSTEM_SERVICE\"}}}";
AuditMessage exploreAccess = new AuditMessage(2500L, new NamespaceId("ns1").dataset("ds1"), "user1", AuditType.ACCESS, new AccessPayload(AccessType.UNKNOWN, new SystemServiceId("explore")));
Assert.assertEquals(jsonToMap(exploreAccessJson), jsonToMap(GSON.toJson(exploreAccess)));
Assert.assertEquals(exploreAccess, GSON.fromJson(exploreAccessJson, AuditMessage.class));
}
Aggregations