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));
}
}
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());
}
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());
}
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);
}
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);
}
}
Aggregations