use of co.cask.cdap.proto.id.FlowId in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method deleteFlowQueues.
/**
* Deletes queues.
*/
@DELETE
@Path("/apps/{app-id}/flows/{flow-id}/queues")
public void deleteFlowQueues(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("flow-id") String flowId) throws Exception {
FlowId flow = new FlowId(namespaceId, appId, flowId);
try {
ProgramStatus status = lifecycleService.getProgramStatus(flow);
if (ProgramStatus.RUNNING == status) {
responder.sendString(HttpResponseStatus.FORBIDDEN, "Flow is running, please stop it first.");
} else {
queueAdmin.dropAllForFlow(flow);
FlowUtils.deleteFlowPendingMetrics(metricStore, namespaceId, appId, flowId);
responder.sendStatus(HttpResponseStatus.OK);
}
} catch (SecurityException e) {
responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
}
}
use of co.cask.cdap.proto.id.FlowId in project cdap by caskdata.
the class QueryClientTest method testAll.
@Test
public void testAll() throws Exception {
NamespaceId namespace = new NamespaceId("queryClientTestNamespace");
NamespaceId otherNamespace = new NamespaceId("queryClientOtherNamespace");
namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
ApplicationId app = namespace.app(FakeApp.NAME);
FlowId flow = app.flow(FakeFlow.NAME);
DatasetId dataset = namespace.dataset(FakeApp.DS_NAME);
appClient.deploy(namespace, createAppJarFile(FakeApp.class));
try {
programClient.start(flow);
assertProgramRunning(programClient, flow);
StreamId stream = namespace.stream(FakeApp.STREAM_NAME);
streamClient.sendEvent(stream, "bob:123");
streamClient.sendEvent(stream, "joe:321");
Thread.sleep(3000);
executeBasicQuery(namespace, FakeApp.DS_NAME);
exploreClient.disableExploreDataset(dataset).get();
try {
queryClient.execute(namespace, "select * from " + FakeApp.DS_NAME).get();
Assert.fail("Explore Query should have thrown an ExecutionException since explore is disabled");
} catch (ExecutionException e) {
// ignored
}
exploreClient.enableExploreDataset(dataset).get();
executeBasicQuery(namespace, FakeApp.DS_NAME);
try {
queryClient.execute(otherNamespace, "show tables").get();
Assert.fail("Explore Query should have thrown an ExecutionException since the database should not exist");
} catch (ExecutionException e) {
// expected
}
} finally {
programClient.stop(flow);
assertProgramStopped(programClient, flow);
try {
appClient.delete(app);
} catch (Exception e) {
LOG.error("Error deleting app {} during test cleanup.", e);
}
}
}
use of co.cask.cdap.proto.id.FlowId 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.FlowId in project cdap by caskdata.
the class FlowQueuePendingCorrector method main.
public static void main(String[] args) throws Exception {
CommandLine cmd = parseArgs(args);
FlowQueuePendingCorrector corrector = createCorrector();
corrector.startAndWait();
try {
String namespace = cmd.getOptionValue("namespace");
String app = cmd.getOptionValue("app");
String flow = cmd.getOptionValue("flow");
if (!cmd.hasOption("namespace")) {
corrector.run();
} else if (!cmd.hasOption("app")) {
corrector.run(new NamespaceId(cmd.getOptionValue("namespace")));
} else if (!cmd.hasOption("flow")) {
Preconditions.checkArgument(cmd.hasOption("namespace"));
corrector.run(new ApplicationId(cmd.getOptionValue("namespace"), cmd.getOptionValue("app")));
} else if (!cmd.hasOption("producer-flowlet") && !cmd.hasOption("consumer-flowlet")) {
corrector.run(new FlowId(cmd.getOptionValue("namespace"), cmd.getOptionValue("app"), cmd.getOptionValue("flow")));
} else {
Preconditions.checkArgument(cmd.hasOption("producer-flowlet"), "Missing producer-flowlet option");
Preconditions.checkArgument(cmd.hasOption("consumer-flowlet"), "Missing consumer-flowlet option");
String producerFlowlet = cmd.getOptionValue("producer-flowlet");
String consumerFlowlet = cmd.getOptionValue("consumer-flowlet");
String queue = cmd.getOptionValue("queue", "queue");
corrector.run(new FlowId(namespace, app, flow), producerFlowlet, consumerFlowlet, queue);
}
} finally {
corrector.stopAndWait();
}
}
use of co.cask.cdap.proto.id.FlowId in project cdap by caskdata.
the class ProgramClientTestRun method testAll.
@Test
public void testAll() throws Exception {
NamespaceId namespace = NamespaceId.DEFAULT;
ApplicationId app = namespace.app(FakeApp.NAME);
FlowId flow = app.flow(FakeFlow.NAME);
FlowletId flowlet = flow.flowlet(FakeFlow.FLOWLET_NAME);
appClient.deploy(namespace, createAppJarFile(FakeApp.class));
try {
// start, scale, and stop flow
verifyProgramNames(FakeApp.FLOWS, appClient.listPrograms(app, ProgramType.FLOW));
LOG.info("Starting flow");
programClient.start(flow);
assertProgramRunning(programClient, flow);
LOG.info("Getting flow history");
programClient.getAllProgramRuns(flow, 0, Long.MAX_VALUE, Integer.MAX_VALUE);
LOG.info("Scaling flowlet");
Assert.assertEquals(1, programClient.getFlowletInstances(flowlet));
programClient.setFlowletInstances(flowlet, 3);
assertFlowletInstances(programClient, flowlet, 3);
List<BatchProgram> statusRequest = new ArrayList<>();
for (ProgramRecord programRecord : appClient.listPrograms(app)) {
statusRequest.add(BatchProgram.from(programRecord));
}
List<BatchProgramStatus> statuses = programClient.getStatus(namespace, statusRequest);
for (BatchProgramStatus status : statuses) {
if (status.getProgramType() == ProgramType.FLOW && status.getProgramId().equals(FakeFlow.NAME)) {
Assert.assertEquals("RUNNING", status.getStatus());
} else {
Assert.assertEquals("STOPPED", status.getStatus());
}
}
LOG.info("Stopping flow");
programClient.stop(flow);
assertProgramStopped(programClient, flow);
testWorkflowCommand(app.workflow(FakeWorkflow.NAME));
LOG.info("Starting flow with debug");
programClient.start(flow, true);
assertProgramRunning(programClient, flow);
programClient.stop(flow);
assertProgramStopped(programClient, flow);
} finally {
try {
appClient.delete(app);
} catch (Exception e) {
LOG.error("Error deleting app {} during test cleanup.", app, e);
}
}
}
Aggregations