Search in sources :

Example 1 with SchemaGenerator

use of co.cask.cdap.internal.io.SchemaGenerator in project cdap by caskdata.

the class FlowUtils method getAllConsumerGroups.

/**
 * Gets all consumer group configurations for the given queue.
 */
private static Set<ConsumerGroupConfig> getAllConsumerGroups(Program program, FlowSpecification flowSpec, QueueName queueName, Table<QueueSpecificationGenerator.Node, String, Set<QueueSpecification>> queueSpecs) {
    Set<ConsumerGroupConfig> groupConfigs = Sets.newHashSet();
    SchemaGenerator schemaGenerator = new ReflectionSchemaGenerator();
    // Get all the consumers of this queue.
    for (Map.Entry<String, FlowletDefinition> entry : flowSpec.getFlowlets().entrySet()) {
        String flowletId = entry.getKey();
        for (QueueSpecification queueSpec : Iterables.concat(queueSpecs.column(flowletId).values())) {
            if (!queueSpec.getQueueName().equals(queueName)) {
                continue;
            }
            try {
                // Inspect the flowlet consumer
                FlowletDefinition flowletDefinition = entry.getValue();
                Class<?> flowletClass = program.getClassLoader().loadClass(flowletDefinition.getFlowletSpec().getClassName());
                long groupId = generateConsumerGroupId(program.getId(), flowletId);
                addConsumerGroup(queueSpec, flowletClass, groupId, flowletDefinition.getInstances(), schemaGenerator, groupConfigs);
            } catch (ClassNotFoundException e) {
                // There is no way for not able to load a Flowlet class as it should be verified during deployment.
                throw Throwables.propagate(e);
            }
        }
    }
    return groupConfigs;
}
Also used : FlowletDefinition(co.cask.cdap.api.flow.FlowletDefinition) SchemaGenerator(co.cask.cdap.internal.io.SchemaGenerator) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) QueueSpecification(co.cask.cdap.app.queue.QueueSpecification) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) ConsumerGroupConfig(co.cask.cdap.data2.queue.ConsumerGroupConfig) Map(java.util.Map)

Aggregations

FlowletDefinition (co.cask.cdap.api.flow.FlowletDefinition)1 QueueSpecification (co.cask.cdap.app.queue.QueueSpecification)1 ConsumerGroupConfig (co.cask.cdap.data2.queue.ConsumerGroupConfig)1 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)1 SchemaGenerator (co.cask.cdap.internal.io.SchemaGenerator)1 Map (java.util.Map)1