Search in sources :

Example 1 with ProcessMethodExtractor

use of co.cask.cdap.internal.specification.ProcessMethodExtractor in project cdap by caskdata.

the class DefaultFlowConfigurer method addFlowlet.

@Override
public void addFlowlet(String name, Flowlet flowlet, int instances) {
    Preconditions.checkNotNull(flowlet, UserMessages.getMessage(UserErrors.INVALID_FLOWLET_NULL));
    DefaultFlowletConfigurer flowletConfigurer = new DefaultFlowletConfigurer(flowlet);
    flowlet.configure(flowletConfigurer);
    FlowletSpecification flowletSpecification = flowletConfigurer.createSpecification();
    Map<String, Set<Type>> inputTypes = new HashMap<>();
    Map<String, Set<Type>> outputTypes = new HashMap<>();
    Reflections.visit(flowlet, flowlet.getClass(), new OutputEmitterFieldExtractor(outputTypes), new ProcessMethodExtractor(inputTypes));
    FlowletDefinition flowletDef = new FlowletDefinition(name, inputTypes, outputTypes, flowletSpecification, instances);
    String flowletName = flowletDef.getFlowletSpec().getName();
    Preconditions.checkArgument(instances > 0, String.format(UserMessages.getMessage(UserErrors.INVALID_INSTANCES), flowletName, instances));
    Preconditions.checkArgument(!flowlets.containsKey(flowletName), UserMessages.getMessage(UserErrors.INVALID_FLOWLET_EXISTS), flowletName);
    flowlets.put(flowletName, flowletDef);
    addStreams(flowletConfigurer.getStreams());
    addDatasetSpecs(flowletConfigurer.getDatasetSpecs());
    addDatasetModules(flowletConfigurer.getDatasetModules());
}
Also used : FlowletDefinition(co.cask.cdap.api.flow.FlowletDefinition) Set(java.util.Set) HashMap(java.util.HashMap) FlowletSpecification(co.cask.cdap.api.flow.flowlet.FlowletSpecification) ProcessMethodExtractor(co.cask.cdap.internal.specification.ProcessMethodExtractor) OutputEmitterFieldExtractor(co.cask.cdap.internal.specification.OutputEmitterFieldExtractor)

Aggregations

FlowletDefinition (co.cask.cdap.api.flow.FlowletDefinition)1 FlowletSpecification (co.cask.cdap.api.flow.flowlet.FlowletSpecification)1 OutputEmitterFieldExtractor (co.cask.cdap.internal.specification.OutputEmitterFieldExtractor)1 ProcessMethodExtractor (co.cask.cdap.internal.specification.ProcessMethodExtractor)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1