Search in sources :

Example 1 with EcoTopologyDefinition

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

the class HeronEcoBuilderTest 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 2 with EcoTopologyDefinition

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

the class EcoParserTest method testParseFromInputStream_VerifyComponents_MapsAsExpected.

@Test
public void testParseFromInputStream_VerifyComponents_MapsAsExpected() throws Exception {
    InputStream inputStream = new ByteArrayInputStream(YAML_STR_1.getBytes());
    FileInputStream mockPropsStream = PowerMockito.mock(FileInputStream.class);
    EcoTopologyDefinition topologyDefinition = subject.parseFromInputStream(inputStream, mockPropsStream, false);
    List<BeanDefinition> components = topologyDefinition.getComponents();
    assertEquals("kafka-topology", topologyDefinition.getName());
    assertEquals("heron", topologyDefinition.getType());
    assertEquals(4, components.size());
    BeanDefinition stringSchemeComponent = components.get(0);
    assertEquals("stringScheme", stringSchemeComponent.getId());
    assertEquals("org.apache.storm.kafka.StringScheme", stringSchemeComponent.getClassName());
    BeanDefinition stringMultiSchemeComponent = components.get(1);
    assertEquals("stringMultiScheme", stringMultiSchemeComponent.getId());
    assertEquals("org.apache.storm.spout.SchemeAsMultiScheme", stringMultiSchemeComponent.getClassName());
    assertEquals(1, stringMultiSchemeComponent.getConstructorArgs().size());
    BeanReference multiStringReference = (BeanReference) stringMultiSchemeComponent.getConstructorArgs().get(0);
    assertEquals("stringScheme", multiStringReference.getId());
    BeanDefinition zkHostsComponent = components.get(2);
    assertEquals("zkHosts", zkHostsComponent.getId());
    assertEquals("org.apache.storm.kafka.ZkHosts", zkHostsComponent.getClassName());
    assertEquals(1, zkHostsComponent.getConstructorArgs().size());
    assertEquals("localhost:2181", zkHostsComponent.getConstructorArgs().get(0));
    BeanDefinition spoutConfigComponent = components.get(3);
    List<Object> spoutConstructArgs = spoutConfigComponent.getConstructorArgs();
    assertEquals("spoutConfig", spoutConfigComponent.getId());
    assertEquals("org.apache.storm.kafka.SpoutConfig", spoutConfigComponent.getClassName());
    BeanReference spoutBrokerHostComponent = (BeanReference) spoutConstructArgs.get(0);
    assertEquals("zkHosts", spoutBrokerHostComponent.getId());
    assertEquals("myKafkaTopic", spoutConstructArgs.get(1));
    assertEquals("/kafkaSpout", spoutConstructArgs.get(2));
    List<PropertyDefinition> properties = spoutConfigComponent.getProperties();
    assertEquals("ignoreZkOffsets", properties.get(0).getName());
    assertEquals(true, properties.get(0).getValue());
    assertEquals("scheme", properties.get(1).getName());
    assertEquals(true, properties.get(1).isReference());
    assertEquals("stringMultiScheme", properties.get(1).getRef());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BeanReference(org.apache.heron.eco.definition.BeanReference) EcoTopologyDefinition(org.apache.heron.eco.definition.EcoTopologyDefinition) BeanDefinition(org.apache.heron.eco.definition.BeanDefinition) PropertyDefinition(org.apache.heron.eco.definition.PropertyDefinition) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 3 with EcoTopologyDefinition

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

the class BoltBuilderTest method testBuildBolts_AllGood_BehavesAsExpected.

@Test
public void testBuildBolts_AllGood_BehavesAsExpected() throws ClassNotFoundException, InvocationTargetException, NoSuchFieldException, InstantiationException, IllegalAccessException {
    EcoTopologyDefinition ecoTopologyDefinition = new EcoTopologyDefinition();
    BoltDefinition boltDefinition = new BoltDefinition();
    final String id = "id";
    boltDefinition.setId(id);
    BoltDefinition boltDefinition1 = new BoltDefinition();
    final String id1 = "id1";
    boltDefinition1.setId(id1);
    List<BoltDefinition> boltDefinitions = new ArrayList<>();
    boltDefinitions.add(boltDefinition);
    boltDefinitions.add(boltDefinition1);
    ecoTopologyDefinition.setBolts(boltDefinitions);
    Object object = new Object();
    Object object1 = new Object();
    when(mockContext.getTopologyDefinition()).thenReturn(ecoTopologyDefinition);
    when(mockObjectBuilder.buildObject(eq(boltDefinition), eq(mockContext))).thenReturn(object);
    when(mockObjectBuilder.buildObject(eq(boltDefinition1), eq(mockContext))).thenReturn(object1);
    subject.buildBolts(mockContext, mockObjectBuilder);
    verify(mockContext).getTopologyDefinition();
    verify(mockObjectBuilder).buildObject(same(boltDefinition), same(mockContext));
    verify(mockObjectBuilder).buildObject(same(boltDefinition1), same(mockContext));
    verify(mockContext).addBolt(eq(id), anyObject());
    verify(mockContext).addBolt(eq(id1), anyObject());
}
Also used : BoltDefinition(org.apache.heron.eco.definition.BoltDefinition) ArrayList(java.util.ArrayList) Matchers.anyObject(org.mockito.Matchers.anyObject) EcoTopologyDefinition(org.apache.heron.eco.definition.EcoTopologyDefinition) Test(org.junit.Test)

Example 4 with EcoTopologyDefinition

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

the class EcoParser method loadTopologyFromYaml.

private EcoTopologyDefinition loadTopologyFromYaml(Yaml yaml, InputStream inputStream, InputStream propsIn, boolean envFilter) throws IOException {
    LOG.info("Parsing eco config file");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    int b;
    while ((b = inputStream.read()) != -1) {
        bos.write(b);
    }
    String yamlDefinitionStr = bos.toString();
    // properties file substitution
    if (propsIn != null) {
        LOG.info("Performing property substitution.");
        Properties props = new Properties();
        props.load(propsIn);
        for (Object key : props.keySet()) {
            yamlDefinitionStr = yamlDefinitionStr.replace("${" + key + "}", props.getProperty((String) key));
        }
    } else {
        LOG.info("Not performing property substitution.");
    }
    // environment variable substitution
    if (envFilter) {
        LOG.info("Performing environment variable substitution.");
        Map<String, String> envs = System.getenv();
        for (String key : envs.keySet()) {
            yamlDefinitionStr = yamlDefinitionStr.replace("${ENV-" + key + "}", envs.get(key));
        }
    } else {
        LOG.info("Not performing environment variable substitution.");
    }
    return (EcoTopologyDefinition) yaml.load(yamlDefinitionStr);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) EcoTopologyDefinition(org.apache.heron.eco.definition.EcoTopologyDefinition) Properties(java.util.Properties)

Example 5 with EcoTopologyDefinition

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

the class ConfigBuilderTest method testBuildConfig_IncorrectComponentJVMOptions_ExceptionThrown.

@Test(expected = IllegalArgumentException.class)
public void testBuildConfig_IncorrectComponentJVMOptions_ExceptionThrown() throws Exception {
    Config config = null;
    try {
        EcoParser ecoParser = new EcoParser();
        InputStream inputStream = new ByteArrayInputStream(INCORRECT_JVM_OPTIONS_CONFIG.getBytes());
        FileInputStream mockPropsStream = PowerMockito.mock(FileInputStream.class);
        EcoTopologyDefinition ecoTopologyDefinition = ecoParser.parseFromInputStream(inputStream, mockPropsStream, false);
        config = subject.buildConfig(ecoTopologyDefinition);
    } finally {
        assertNull(config);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Config(org.apache.heron.api.Config) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EcoParser(org.apache.heron.eco.parser.EcoParser) EcoTopologyDefinition(org.apache.heron.eco.definition.EcoTopologyDefinition) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

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