Search in sources :

Example 21 with EcoTopologyDefinition

use of com.twitter.heron.eco.definition.EcoTopologyDefinition in project incubator-heron by apache.

the class ConfigBuilderTest method testBuildConfig_MBAllocationTooSmall_ExceptionThrown.

@Test(expected = IllegalArgumentException.class)
public void testBuildConfig_MBAllocationTooSmall_ExceptionThrown() throws Exception {
    Config config = null;
    try {
        EcoParser ecoParser = new EcoParser();
        InputStream inputStream = new ByteArrayInputStream(INCORRECT_RAM_MEGABYTES.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(com.twitter.heron.api.Config) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EcoParser(com.twitter.heron.eco.parser.EcoParser) EcoTopologyDefinition(com.twitter.heron.eco.definition.EcoTopologyDefinition) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 22 with EcoTopologyDefinition

use of com.twitter.heron.eco.definition.EcoTopologyDefinition in project incubator-heron by apache.

the class EcoParserTest method testParseFromInputStream_PropertyFiltering_SubstitutesAsExpected.

@Test
public void testParseFromInputStream_PropertyFiltering_SubstitutesAsExpected() throws Exception {
    InputStream inputStream = new ByteArrayInputStream(PROPERTY_SUBSTITUION_YAML.getBytes());
    InputStream propsStream = new ByteArrayInputStream(SAMPLE_PROPERTIES.getBytes());
    EcoTopologyDefinition ecoTopologyDefinition = subject.parseFromInputStream(inputStream, propsStream, false);
    BoltDefinition bolt = ecoTopologyDefinition.getBolt("ibasic-print-bolt");
    List<Object> args = bolt.getConfigMethods().get(0).getArgs();
    assertThat(args.get(0), is(equalTo("ecoValueOne")));
}
Also used : BoltDefinition(com.twitter.heron.eco.definition.BoltDefinition) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EcoTopologyDefinition(com.twitter.heron.eco.definition.EcoTopologyDefinition) Test(org.junit.Test)

Example 23 with EcoTopologyDefinition

use of com.twitter.heron.eco.definition.EcoTopologyDefinition in project incubator-heron by apache.

the class Eco method printTopologyInfo.

static void printTopologyInfo(EcoExecutionContext ctx) {
    EcoTopologyDefinition t = ctx.getTopologyDefinition();
    LOG.info("---------- TOPOLOGY DETAILS ----------");
    LOG.info(String.format("Topology Name: %s", t.getName()));
    LOG.info("--------------- SPOUTS ---------------");
    for (SpoutDefinition s : t.getSpouts()) {
        LOG.info(String.format("%s [%d] (%s)", s.getId(), s.getParallelism(), s.getClassName()));
    }
    LOG.info("---------------- BOLTS ---------------");
    for (BoltDefinition b : t.getBolts()) {
        LOG.info(String.format("%s [%d] (%s)", b.getId(), b.getParallelism(), b.getClassName()));
    }
    LOG.info("--------------- STREAMS ---------------");
    for (StreamDefinition sd : t.getStreams()) {
        LOG.info(String.format("%s --%s--> %s", sd.getFrom(), sd.getGrouping().getType(), sd.getTo()));
    }
    LOG.info("--------------------------------------");
}
Also used : BoltDefinition(com.twitter.heron.eco.definition.BoltDefinition) StreamDefinition(com.twitter.heron.eco.definition.StreamDefinition) EcoTopologyDefinition(com.twitter.heron.eco.definition.EcoTopologyDefinition) SpoutDefinition(com.twitter.heron.eco.definition.SpoutDefinition)

Example 24 with EcoTopologyDefinition

use of com.twitter.heron.eco.definition.EcoTopologyDefinition in project incubator-heron by apache.

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(com.twitter.heron.eco.definition.EcoTopologyDefinition) Properties(java.util.Properties)

Example 25 with EcoTopologyDefinition

use of com.twitter.heron.eco.definition.EcoTopologyDefinition in project incubator-heron by apache.

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(com.twitter.heron.eco.definition.ObjectDefinition) EcoTopologyDefinition(com.twitter.heron.eco.definition.EcoTopologyDefinition)

Aggregations

EcoTopologyDefinition (com.twitter.heron.eco.definition.EcoTopologyDefinition)26 Test (org.junit.Test)19 FileInputStream (java.io.FileInputStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 InputStream (java.io.InputStream)13 Config (com.twitter.heron.api.Config)12 EcoParser (com.twitter.heron.eco.parser.EcoParser)8 BoltDefinition (com.twitter.heron.eco.definition.BoltDefinition)4 StreamDefinition (com.twitter.heron.eco.definition.StreamDefinition)3 ArrayList (java.util.ArrayList)3 ObjectBuilder (com.twitter.heron.eco.builder.ObjectBuilder)2 BeanDefinition (com.twitter.heron.eco.definition.BeanDefinition)2 EcoExecutionContext (com.twitter.heron.eco.definition.EcoExecutionContext)2 GroupingDefinition (com.twitter.heron.eco.definition.GroupingDefinition)2 ObjectDefinition (com.twitter.heron.eco.definition.ObjectDefinition)2 SpoutDefinition (com.twitter.heron.eco.definition.SpoutDefinition)2 HashMap (java.util.HashMap)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2 BuilderUtility (com.twitter.heron.eco.builder.BuilderUtility)1 BeanReference (com.twitter.heron.eco.definition.BeanReference)1