Search in sources :

Example 1 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.

the class FlowProgramRunner method run.

@Override
public ProgramController run(Program program, ProgramOptions options) {
    // Extract and verify parameters
    ApplicationSpecification appSpec = program.getApplicationSpecification();
    Preconditions.checkNotNull(appSpec, "Missing application specification.");
    ProgramType processorType = program.getType();
    Preconditions.checkNotNull(processorType, "Missing processor type.");
    Preconditions.checkArgument(processorType == ProgramType.FLOW, "Only FLOW process type is supported.");
    FlowSpecification flowSpec = appSpec.getFlows().get(program.getName());
    Preconditions.checkNotNull(flowSpec, "Missing FlowSpecification for %s", program.getName());
    try {
        // Launch flowlet program runners
        RunId runId = ProgramRunners.getRunId(options);
        Multimap<String, QueueName> consumerQueues = FlowUtils.configureQueue(program, flowSpec, streamAdmin, queueAdmin, txExecutorFactory);
        final Table<String, Integer, ProgramController> flowlets = createFlowlets(program, options, flowSpec);
        return new FlowProgramController(flowlets, program, options, flowSpec, consumerQueues);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ProgramController(co.cask.cdap.app.runtime.ProgramController) AbstractProgramController(co.cask.cdap.internal.app.runtime.AbstractProgramController) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) ProgramType(co.cask.cdap.proto.ProgramType) RunId(org.apache.twill.api.RunId) QueueName(co.cask.cdap.common.queue.QueueName) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification 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()));
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) HTable(org.apache.hadoop.hbase.client.HTable) Table(com.google.common.collect.Table) ProgramId(co.cask.cdap.proto.id.ProgramId) TransactionNotInProgressException(org.apache.tephra.TransactionNotInProgressException) TransactionFailureException(org.apache.tephra.TransactionFailureException) NotFoundException(co.cask.cdap.common.NotFoundException) SimpleQueueSpecificationGenerator(co.cask.cdap.internal.app.queue.SimpleQueueSpecificationGenerator) SimpleQueueSpecificationGenerator(co.cask.cdap.internal.app.queue.SimpleQueueSpecificationGenerator) QueueSpecificationGenerator(co.cask.cdap.app.queue.QueueSpecificationGenerator) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) QueueSpecification(co.cask.cdap.app.queue.QueueSpecification) ApplicationId(co.cask.cdap.proto.id.ApplicationId)

Example 3 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.

the class FlowQueuePendingCorrector method run.

/**
 * Corrects queue.pending metric for all flowlets in an application.
 */
public void run(ApplicationId appId, ApplicationSpecification appSpec) throws Exception {
    System.out.println("Running queue.pending correction on app " + appId);
    Preconditions.checkArgument(appSpec.getName().equals(appId.getApplication()), String.format("Expected appSpec name '%s' to be equal to appId name '%s'", appSpec.getName(), appId.getApplication()));
    for (FlowSpecification flow : appSpec.getFlows().values()) {
        run(appId.flow(flow.getName()));
    }
}
Also used : FlowSpecification(co.cask.cdap.api.flow.FlowSpecification)

Example 4 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.

the class FlowQueuePendingCorrector method run.

/**
 * Corrects queue.pending metric for a flowlet.
 */
public void run(FlowId flowId, String producerFlowlet, String consumerFlowlet, String flowletQueue) throws Exception {
    ApplicationSpecification app = store.getApplication(flowId.getParent());
    Preconditions.checkArgument(app != null, flowId.getApplication() + " not found");
    Preconditions.checkArgument(app.getFlows().containsKey(flowId.getProgram()), flowId + " not found");
    FlowSpecification flow = app.getFlows().get(flowId.getProgram());
    run(flowId, producerFlowlet, consumerFlowlet, flowletQueue, flow);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification)

Example 5 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.

the class FlowVerificationTest method testFlowMissingConnection.

/**
 * This test that verification of flow connections
 */
@Test
public void testFlowMissingConnection() throws Exception {
    ApplicationSpecification appSpec = Specifications.from(new NoConsumerApp());
    ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
    ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
    FlowVerification flowVerifier = new FlowVerification();
    for (FlowSpecification flowSpec : appSpec.getFlows().values()) {
        VerifyResult result = flowVerifier.verify(new ApplicationId("test", newSpec.getName()), flowSpec);
        Assert.assertTrue(result.getStatus() == VerifyResult.Status.FAILED);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) ApplicationSpecificationAdapter(co.cask.cdap.internal.app.ApplicationSpecificationAdapter) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) VerifyResult(co.cask.cdap.app.verification.VerifyResult) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Aggregations

FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)25 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)15 FlowletDefinition (co.cask.cdap.api.flow.FlowletDefinition)7 ApplicationId (co.cask.cdap.proto.id.ApplicationId)7 ProgramType (co.cask.cdap.proto.ProgramType)5 Test (org.junit.Test)4 VerifyResult (co.cask.cdap.app.verification.VerifyResult)3 ApplicationSpecificationAdapter (co.cask.cdap.internal.app.ApplicationSpecificationAdapter)3 ForwardingFlowSpecification (co.cask.cdap.internal.app.ForwardingFlowSpecification)3 ProgramId (co.cask.cdap.proto.id.ProgramId)3 WebCrawlApp (co.cask.cdap.WebCrawlApp)2 MapReduceSpecification (co.cask.cdap.api.mapreduce.MapReduceSpecification)2 ServiceSpecification (co.cask.cdap.api.service.ServiceSpecification)2 SparkSpecification (co.cask.cdap.api.spark.SparkSpecification)2 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)2 ProgramController (co.cask.cdap.app.runtime.ProgramController)2 NotFoundException (co.cask.cdap.common.NotFoundException)2 QueueName (co.cask.cdap.common.queue.QueueName)2 ForwardingApplicationSpecification (co.cask.cdap.internal.app.ForwardingApplicationSpecification)2 SimpleQueueSpecificationGenerator (co.cask.cdap.internal.app.queue.SimpleQueueSpecificationGenerator)2