Search in sources :

Example 11 with EcoTopologyDefinition

use of org.apache.heron.eco.definition.EcoTopologyDefinition in project heron by twitter.

the class Eco method submit.

/**
 * Submit an ECO topology
 *
 * @param fileInputStream  The input stream associated with ECO topology definition file
 * @param propertiesFile  The optional key-value property file for optional property substitution.
 * @param envFilter The optional flag to tell ECO to perform environment variable substitution
 * @throws Exception the exception thrown
 */
public void submit(FileInputStream fileInputStream, FileInputStream propertiesFile, boolean envFilter) throws Exception {
    EcoTopologyDefinition topologyDefinition = ecoParser.parseFromInputStream(fileInputStream, propertiesFile, envFilter);
    String topologyName = topologyDefinition.getName();
    String topologyType = topologyDefinition.getType();
    if ("storm".equals(topologyType)) {
        System.out.println("topology type is Storm");
        org.apache.heron.eco.builder.storm.EcoBuilder ecoBuilder = new org.apache.heron.eco.builder.storm.EcoBuilder(new org.apache.heron.eco.builder.storm.SpoutBuilder(), new BoltBuilder(), new org.apache.heron.eco.builder.storm.StreamBuilder(), new ComponentBuilder(), new ConfigBuilder());
        Config topologyConfig = ecoBuilder.buildConfig(topologyDefinition);
        EcoExecutionContext executionContext = new EcoExecutionContext(topologyDefinition, topologyConfig);
        printTopologyInfo(executionContext);
        ObjectBuilder objectBuilder = new ObjectBuilder();
        objectBuilder.setBuilderUtility(new BuilderUtility());
        org.apache.storm.topology.TopologyBuilder builder = ecoBuilder.buildTopologyBuilder(executionContext, objectBuilder);
        ecoSubmitter.submitStormTopology(topologyName, topologyConfig, builder.createTopology());
    } else if ("heron".equals(topologyType)) {
        System.out.println("topology type is Heron");
        org.apache.heron.eco.builder.heron.EcoBuilder ecoBuilder = new org.apache.heron.eco.builder.heron.EcoBuilder(new org.apache.heron.eco.builder.heron.SpoutBuilder(), new BoltBuilder(), new org.apache.heron.eco.builder.heron.StreamBuilder(), new ComponentBuilder(), new ConfigBuilder());
        Config topologyConfig = ecoBuilder.buildConfig(topologyDefinition);
        EcoExecutionContext executionContext = new EcoExecutionContext(topologyDefinition, topologyConfig);
        printTopologyInfo(executionContext);
        ObjectBuilder objectBuilder = new ObjectBuilder();
        objectBuilder.setBuilderUtility(new BuilderUtility());
        org.apache.heron.api.topology.TopologyBuilder builder = ecoBuilder.buildTopologyBuilder(executionContext, objectBuilder);
        ecoSubmitter.submitHeronTopology(topologyName, topologyConfig, builder.createTopology());
    } else {
        LOG.log(Level.SEVERE, String.format("Unknown topology type \'%s\' for topology %s, not submitted", topologyType, topologyName));
    }
}
Also used : Config(org.apache.heron.api.Config) EcoTopologyDefinition(org.apache.heron.eco.definition.EcoTopologyDefinition) BuilderUtility(org.apache.heron.eco.builder.BuilderUtility) BoltBuilder(org.apache.heron.eco.builder.BoltBuilder) ConfigBuilder(org.apache.heron.eco.builder.ConfigBuilder) EcoExecutionContext(org.apache.heron.eco.definition.EcoExecutionContext) ObjectBuilder(org.apache.heron.eco.builder.ObjectBuilder) ComponentBuilder(org.apache.heron.eco.builder.ComponentBuilder)

Example 12 with EcoTopologyDefinition

use of org.apache.heron.eco.definition.EcoTopologyDefinition in project heron by twitter.

the class ComponentBuilderTest method testBuildComponents_AllGood_BehavesAsExpected.

@Test
public void testBuildComponents_AllGood_BehavesAsExpected() throws ClassNotFoundException, InvocationTargetException, NoSuchFieldException, InstantiationException, IllegalAccessException {
    BeanDefinition beanDefinition = new BeanDefinition();
    final String id = "bean";
    beanDefinition.setId(id);
    BeanDefinition beanDefinition1 = new BeanDefinition();
    final String id1 = "bean1";
    beanDefinition1.setId(id1);
    List<BeanDefinition> componentDefinitions = new ArrayList<>();
    componentDefinitions.add(beanDefinition);
    componentDefinitions.add(beanDefinition1);
    EcoTopologyDefinition ecoTopologyDefinition = new EcoTopologyDefinition();
    ecoTopologyDefinition.setComponents(componentDefinitions);
    Object object = new Object();
    Object object1 = new Object();
    when(mockContext.getTopologyDefinition()).thenReturn(ecoTopologyDefinition);
    when(mockObjectBuilder.buildObject(eq(beanDefinition), eq(mockContext))).thenReturn(object);
    when(mockObjectBuilder.buildObject(eq(beanDefinition1), eq(mockContext))).thenReturn(object1);
    subject.buildComponents(mockContext, mockObjectBuilder);
    verify(mockContext).getTopologyDefinition();
    verify(mockObjectBuilder).buildObject(same(beanDefinition), same(mockContext));
    verify(mockObjectBuilder).buildObject(same(beanDefinition1), same(mockContext));
    verify(mockContext).addComponent(eq(id), anyObject());
    verify(mockContext).addComponent(eq(id1), anyObject());
}
Also used : ArrayList(java.util.ArrayList) Matchers.anyObject(org.mockito.Matchers.anyObject) EcoTopologyDefinition(org.apache.heron.eco.definition.EcoTopologyDefinition) BeanDefinition(org.apache.heron.eco.definition.BeanDefinition) Test(org.junit.Test)

Example 13 with EcoTopologyDefinition

use of org.apache.heron.eco.definition.EcoTopologyDefinition in project heron by twitter.

the class HeronSpoutBuilderTest method testBuildSpouts_AllGood_BehavesAsExpected.

@Test
public void testBuildSpouts_AllGood_BehavesAsExpected() throws ClassNotFoundException, InvocationTargetException, NoSuchFieldException, InstantiationException, IllegalAccessException {
    EcoTopologyDefinition topologyDefinition = new EcoTopologyDefinition();
    SpoutDefinition spoutDefinition = new SpoutDefinition();
    final String id = "id";
    final int parallelism = 2;
    spoutDefinition.setId(id);
    spoutDefinition.setParallelism(parallelism);
    SpoutDefinition spoutDefinition1 = new SpoutDefinition();
    final String id1 = "id1";
    final int parallelism1 = 3;
    spoutDefinition1.setId(id1);
    spoutDefinition1.setParallelism(parallelism1);
    List<SpoutDefinition> spoutDefinitions = new ArrayList<>();
    spoutDefinitions.add(spoutDefinition);
    spoutDefinitions.add(spoutDefinition1);
    topologyDefinition.setSpouts(spoutDefinitions);
    MockSpout mockSpout = new MockSpout();
    MockSpout mockSpout1 = new MockSpout();
    when(mockObjectBuilder.buildObject(eq(spoutDefinition), eq(mockContext))).thenReturn(mockSpout);
    when(mockObjectBuilder.buildObject(eq(spoutDefinition1), eq(mockContext))).thenReturn(mockSpout1);
    when(mockContext.getTopologyDefinition()).thenReturn(topologyDefinition);
    subject.buildSpouts(mockContext, mockTopologyBuilder, mockObjectBuilder);
    verify(mockContext).getTopologyDefinition();
    verify(mockObjectBuilder).buildObject(same(spoutDefinition), same(mockContext));
    verify(mockObjectBuilder).buildObject(same(spoutDefinition1), same(mockContext));
    verify(mockTopologyBuilder).setSpout(eq(id), eq(mockSpout), eq(parallelism));
    verify(mockTopologyBuilder).setSpout(eq(id1), eq(mockSpout1), eq(parallelism1));
    verify(mockContext).addSpout(eq(id), anyObject());
    verify(mockContext).addSpout(eq(id1), anyObject());
}
Also used : ArrayList(java.util.ArrayList) EcoTopologyDefinition(org.apache.heron.eco.definition.EcoTopologyDefinition) SpoutDefinition(org.apache.heron.eco.definition.SpoutDefinition) Test(org.junit.Test)

Example 14 with EcoTopologyDefinition

use of org.apache.heron.eco.definition.EcoTopologyDefinition in project heron by twitter.

the class StormEcoBuilderTest method setUpForEachTestCase.

@Before
public void setUpForEachTestCase() {
    configMap = new HashMap<>();
    ecoTopologyDefinition = new EcoTopologyDefinition();
    ecoTopologyDefinition.setConfig(configMap);
}
Also used : EcoTopologyDefinition(org.apache.heron.eco.definition.EcoTopologyDefinition) Before(org.junit.Before)

Example 15 with EcoTopologyDefinition

use of org.apache.heron.eco.definition.EcoTopologyDefinition in project heron by twitter.

the class SpoutBuilder method buildSpouts.

protected void buildSpouts(EcoExecutionContext executionContext, TopologyBuilder builder, ObjectBuilder objectBuilder) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchFieldException, InvocationTargetException {
    EcoTopologyDefinition topologyDefinition = executionContext.getTopologyDefinition();
    for (ObjectDefinition def : topologyDefinition.getSpouts()) {
        Object obj = objectBuilder.buildObject(def, executionContext);
        builder.setSpout(def.getId(), (IRichSpout) obj, def.getParallelism());
        executionContext.addSpout(def.getId(), obj);
    }
}
Also used : ObjectDefinition(org.apache.heron.eco.definition.ObjectDefinition) EcoTopologyDefinition(org.apache.heron.eco.definition.EcoTopologyDefinition)

Aggregations

EcoTopologyDefinition (org.apache.heron.eco.definition.EcoTopologyDefinition)31 Test (org.junit.Test)21 FileInputStream (java.io.FileInputStream)15 ByteArrayInputStream (java.io.ByteArrayInputStream)13 InputStream (java.io.InputStream)13 Config (org.apache.heron.api.Config)13 EcoParser (org.apache.heron.eco.parser.EcoParser)8 ArrayList (java.util.ArrayList)4 BoltDefinition (org.apache.heron.eco.definition.BoltDefinition)4 StreamDefinition (org.apache.heron.eco.definition.StreamDefinition)4 HashMap (java.util.HashMap)3 GroupingDefinition (org.apache.heron.eco.definition.GroupingDefinition)3 ObjectDefinition (org.apache.heron.eco.definition.ObjectDefinition)3 SpoutDefinition (org.apache.heron.eco.definition.SpoutDefinition)3 BeanDefinition (org.apache.heron.eco.definition.BeanDefinition)2 ComponentStream (org.apache.heron.eco.definition.ComponentStream)2 Before (org.junit.Before)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Properties (java.util.Properties)1