use of co.cask.cdap.proto.id.ApplicationId 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.ApplicationId 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.ApplicationId in project cdap by caskdata.
the class TestFrameworkTestRun method testAppWithPlugin.
@Test
public void testAppWithPlugin() throws Exception {
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("app-with-plugin", "1.0.0-SNAPSHOT");
addAppArtifact(artifactId, AppWithPlugin.class);
ArtifactId pluginArtifactId = NamespaceId.DEFAULT.artifact("test-plugin", "1.0.0-SNAPSHOT");
addPluginArtifact(pluginArtifactId, artifactId, ToStringPlugin.class);
ApplicationId appId = NamespaceId.DEFAULT.app("AppWithPlugin");
AppRequest createRequest = new AppRequest(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()));
ApplicationManager appManager = deployApplication(appId, createRequest);
final WorkerManager workerManager = appManager.getWorkerManager(AppWithPlugin.WORKER);
workerManager.start();
workerManager.waitForStatus(false, 5, 1);
Tasks.waitFor(false, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return workerManager.getHistory(ProgramRunStatus.COMPLETED).isEmpty();
}
}, 5, TimeUnit.SECONDS, 10, TimeUnit.MILLISECONDS);
final ServiceManager serviceManager = appManager.getServiceManager(AppWithPlugin.SERVICE);
serviceManager.start();
serviceManager.waitForStatus(true, 1, 10);
URL serviceURL = serviceManager.getServiceURL(5, TimeUnit.SECONDS);
callServiceGet(serviceURL, "dummy");
serviceManager.stop();
serviceManager.waitForStatus(false, 1, 10);
Tasks.waitFor(false, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return serviceManager.getHistory(ProgramRunStatus.KILLED).isEmpty();
}
}, 5, TimeUnit.SECONDS, 10, TimeUnit.MILLISECONDS);
WorkflowManager workflowManager = appManager.getWorkflowManager(AppWithPlugin.WORKFLOW);
workflowManager.start();
workflowManager.waitForRun(ProgramRunStatus.COMPLETED, 5, TimeUnit.MINUTES);
List<RunRecord> runRecords = workflowManager.getHistory();
Assert.assertNotEquals(ProgramRunStatus.FAILED, runRecords.get(0).getStatus());
DataSetManager<KeyValueTable> workflowTableManager = getDataset(AppWithPlugin.WORKFLOW_TABLE);
String value = Bytes.toString(workflowTableManager.get().read("val"));
Assert.assertEquals(AppWithPlugin.TEST, value);
Map<String, String> workflowTags = ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, NamespaceId.DEFAULT.getNamespace(), Constants.Metrics.Tag.APP, "AppWithPlugin", Constants.Metrics.Tag.WORKFLOW, AppWithPlugin.WORKFLOW, Constants.Metrics.Tag.RUN_ID, runRecords.get(0).getPid());
getMetricsManager().waitForTotalMetricCount(workflowTags, String.format("user.destroy.%s", AppWithPlugin.WORKFLOW), 1, 60, TimeUnit.SECONDS);
// Testing Spark Plugins. First send some data to stream for the Spark program to process
StreamManager streamManager = getStreamManager(AppWithPlugin.SPARK_STREAM);
for (int i = 0; i < 5; i++) {
streamManager.send("Message " + i);
}
SparkManager sparkManager = appManager.getSparkManager(AppWithPlugin.SPARK).start();
sparkManager.waitForRun(ProgramRunStatus.COMPLETED, 2, TimeUnit.MINUTES);
// Verify the Spark result.
DataSetManager<Table> dataSetManager = getDataset(AppWithPlugin.SPARK_TABLE);
Table table = dataSetManager.get();
try (Scanner scanner = table.scan(null, null)) {
for (int i = 0; i < 5; i++) {
Row row = scanner.next();
Assert.assertNotNull(row);
String expected = "Message " + i + " " + AppWithPlugin.TEST;
Assert.assertEquals(expected, Bytes.toString(row.getRow()));
Assert.assertEquals(expected, Bytes.toString(row.get(expected)));
}
// There shouldn't be any more rows in the table.
Assert.assertNull(scanner.next());
}
}
use of co.cask.cdap.proto.id.ApplicationId in project cdap by caskdata.
the class TestFrameworkTestRun method testAppFromArtifact.
@Test
public void testAppFromArtifact() throws Exception {
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("cfg-app", "1.0.0-SNAPSHOT");
addAppArtifact(artifactId, ConfigTestApp.class);
ApplicationId appId = NamespaceId.DEFAULT.app("AppFromArtifact");
AppRequest<ConfigTestApp.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("testStream", "testDataset"));
ApplicationManager appManager = deployApplication(appId, createRequest);
testAppConfig(appId.getApplication(), appManager, createRequest.getConfig());
}
use of co.cask.cdap.proto.id.ApplicationId in project cdap by caskdata.
the class ProgramExistenceVerifier method ensureExists.
@Override
public void ensureExists(ProgramId programId) throws ApplicationNotFoundException, ProgramNotFoundException {
ApplicationId appId = programId.getParent();
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new ApplicationNotFoundException(appId);
}
ProgramType programType = programId.getType();
Set<String> programNames = null;
if (programType == ProgramType.FLOW && appSpec.getFlows() != null) {
programNames = appSpec.getFlows().keySet();
} else if (programType == ProgramType.MAPREDUCE && appSpec.getMapReduce() != null) {
programNames = appSpec.getMapReduce().keySet();
} else if (programType == ProgramType.WORKFLOW && appSpec.getWorkflows() != null) {
programNames = appSpec.getWorkflows().keySet();
} else if (programType == ProgramType.SERVICE && appSpec.getServices() != null) {
programNames = appSpec.getServices().keySet();
} else if (programType == ProgramType.SPARK && appSpec.getSpark() != null) {
programNames = appSpec.getSpark().keySet();
} else if (programType == ProgramType.WORKER && appSpec.getWorkers() != null) {
programNames = appSpec.getWorkers().keySet();
}
if (programNames != null) {
if (programNames.contains(programId.getProgram())) {
// is valid.
return;
}
}
throw new ProgramNotFoundException(programId);
}
Aggregations