Search in sources :

Example 36 with StormTopology

use of org.apache.storm.generated.StormTopology in project storm by apache.

the class StormCommon method validateIds.

@SuppressWarnings("unchecked")
private static void validateIds(StormTopology topology) throws InvalidTopologyException {
    List<String> componentIds = new ArrayList<>();
    for (StormTopology._Fields field : Thrift.getTopologyFields()) {
        if (!ThriftTopologyUtils.isWorkerHook(field) && !ThriftTopologyUtils.isDependencies(field)) {
            Object value = topology.getFieldValue(field);
            Map<String, Object> componentMap = (Map<String, Object>) value;
            componentIds.addAll(componentMap.keySet());
            for (String id : componentMap.keySet()) {
                if (Utils.isSystemId(id)) {
                    throw new InvalidTopologyException(id + " is not a valid component id.");
                }
            }
            for (Object componentObj : componentMap.values()) {
                ComponentCommon common = getComponentCommon(componentObj);
                Set<String> streamIds = common.get_streams().keySet();
                for (String id : streamIds) {
                    if (Utils.isSystemId(id)) {
                        throw new InvalidTopologyException(id + " is not a valid stream id.");
                    }
                }
            }
        }
    }
    List<String> offending = Utils.getRepeat(componentIds);
    if (!offending.isEmpty()) {
        throw new InvalidTopologyException("Duplicate component ids: " + offending);
    }
}
Also used : ComponentCommon(org.apache.storm.generated.ComponentCommon) StormTopology(org.apache.storm.generated.StormTopology) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 37 with StormTopology

use of org.apache.storm.generated.StormTopology in project metron by apache.

the class FluxTopologyComponent method startTopology.

private void startTopology(String topologyName, File topologyLoc, File templateFile, Properties properties) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, TException, NoSuchFieldException {
    TopologyDef topologyDef = loadYaml(topologyName, topologyLoc, templateFile, properties);
    Config conf = FluxBuilder.buildConfig(topologyDef);
    ExecutionContext context = new ExecutionContext(topologyDef, conf);
    StormTopology topology = FluxBuilder.buildTopology(context);
    Assert.assertNotNull(topology);
    topology.validate();
    try {
        stormCluster.submitTopology(topologyName, conf, topology);
    } catch (Exception nne) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }
        stormCluster.submitTopology(topologyName, conf, topology);
    }
}
Also used : TopologyDef(org.apache.storm.flux.model.TopologyDef) ExecutionContext(org.apache.storm.flux.model.ExecutionContext) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) UnableToStartException(org.apache.metron.integration.UnableToStartException) IOException(java.io.IOException) TException(org.apache.storm.thrift.TException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 38 with StormTopology

use of org.apache.storm.generated.StormTopology in project storm by apache.

the class TridentMinMaxOfVehiclesTopology method main.

public static void main(String[] args) throws Exception {
    StormTopology topology = buildVehiclesTopology();
    Config conf = new Config();
    conf.setMaxSpoutPending(20);
    if (args.length == 0) {
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("vehicles-topology", conf, topology)) {
            Utils.sleep(60 * 1000);
        }
        System.exit(0);
    } else {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopologyWithProgressBar("vehicles-topology", conf, topology);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 39 with StormTopology

use of org.apache.storm.generated.StormTopology in project storm by apache.

the class TCKTest method testBadShellComponents.

@Test(expected = IllegalArgumentException.class)
public void testBadShellComponents() throws Exception {
    TopologyDef topologyDef = FluxParser.parseResource("/configs/bad_shell_test.yaml", false, true, null, false);
    Config conf = FluxBuilder.buildConfig(topologyDef);
    ExecutionContext context = new ExecutionContext(topologyDef, conf);
    StormTopology topology = FluxBuilder.buildTopology(context);
    assertNotNull(topology);
    topology.validate();
}
Also used : TopologyDef(org.apache.storm.flux.model.TopologyDef) ExecutionContext(org.apache.storm.flux.model.ExecutionContext) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) Test(org.junit.Test)

Example 40 with StormTopology

use of org.apache.storm.generated.StormTopology in project storm by apache.

the class TCKTest method testTopologySource.

@Test
public void testTopologySource() throws Exception {
    TopologyDef topologyDef = FluxParser.parseResource("/configs/existing-topology.yaml", false, true, null, false);
    assertTrue(topologyDef.validate());
    Config conf = FluxBuilder.buildConfig(topologyDef);
    ExecutionContext context = new ExecutionContext(topologyDef, conf);
    StormTopology topology = FluxBuilder.buildTopology(context);
    assertNotNull(topology);
    topology.validate();
}
Also used : TopologyDef(org.apache.storm.flux.model.TopologyDef) ExecutionContext(org.apache.storm.flux.model.ExecutionContext) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) Test(org.junit.Test)

Aggregations

StormTopology (org.apache.storm.generated.StormTopology)76 Test (org.junit.Test)45 Config (org.apache.storm.Config)38 HashMap (java.util.HashMap)31 ExecutionContext (org.apache.storm.flux.model.ExecutionContext)20 TopologyDef (org.apache.storm.flux.model.TopologyDef)20 Map (java.util.Map)17 ArrayList (java.util.ArrayList)14 Bolt (org.apache.storm.generated.Bolt)13 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)13 List (java.util.List)11 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)11 Grouping (org.apache.storm.generated.Grouping)10 SpoutSpec (org.apache.storm.generated.SpoutSpec)10 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)10 NullStruct (org.apache.storm.generated.NullStruct)9 INimbus (org.apache.storm.scheduler.INimbus)9 IRichBolt (org.apache.storm.topology.IRichBolt)9 Cluster (org.apache.storm.scheduler.Cluster)8 ExecutorDetails (org.apache.storm.scheduler.ExecutorDetails)8