Search in sources :

Example 26 with OperatorMeta

use of com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta in project apex-core by apache.

the class LogicalPlanConfigurationTest method dagOperatorAttributeHelper.

private void dagOperatorAttributeHelper(boolean attrOnDag) {
    String attributeName = null;
    if (attrOnDag) {
        attributeName = DAGContext.CHECKPOINT_WINDOW_COUNT.getSimpleName();
    } else {
        attributeName = OperatorContext.class.getCanonicalName() + LogicalPlanConfiguration.KEY_SEPARATOR + DAGContext.CHECKPOINT_WINDOW_COUNT.getSimpleName();
    }
    Properties props = new Properties();
    String propName = StreamingApplication.APEX_PREFIX + StramElement.ATTR.getValue() + LogicalPlanConfiguration.KEY_SEPARATOR + attributeName;
    props.put(propName, "5");
    SimpleTestApplicationWithName app = new SimpleTestApplicationWithName();
    LogicalPlanConfiguration dagBuilder = new LogicalPlanConfiguration(new Configuration(false));
    dagBuilder.addFromProperties(props, null);
    String appPath = app.getClass().getName().replace(".", "/") + ".class";
    LogicalPlan dag = new LogicalPlan();
    dagBuilder.prepareDAG(dag, app, appPath);
    OperatorMeta om1 = dag.getOperatorMeta("operator1");
    if (attrOnDag) {
        Assert.assertNotEquals((Integer) 5, om1.getValue(OperatorContext.CHECKPOINT_WINDOW_COUNT));
    } else {
        Assert.assertEquals((Integer) 5, om1.getValue(OperatorContext.CHECKPOINT_WINDOW_COUNT));
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) OperatorContext(com.datatorrent.api.Context.OperatorContext) Integer2String(com.datatorrent.api.StringCodec.Integer2String) Properties(java.util.Properties)

Example 27 with OperatorMeta

use of com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta in project apex-core by apache.

the class LogicalPlanConfigurationTest method testTupleClassAttr.

@Test
public void testTupleClassAttr() throws Exception {
    String resourcePath = "/schemaTestTopology.json";
    InputStream is = this.getClass().getResourceAsStream(resourcePath);
    if (is == null) {
        fail("Could not load " + resourcePath);
    }
    StringWriter writer = new StringWriter();
    IOUtils.copy(is, writer);
    JSONObject json = new JSONObject(writer.toString());
    Configuration conf = new Configuration(false);
    LogicalPlanConfiguration planConf = new LogicalPlanConfiguration(conf);
    LogicalPlan dag = planConf.createFromJson(json, "testLoadFromJson");
    dag.validate();
    OperatorMeta operator1 = dag.getOperatorMeta("operator1");
    assertEquals("operator1.classname", SchemaTestOperator.class, operator1.getOperator().getClass());
    StreamMeta input1 = dag.getStream("inputStream");
    assertNotNull(input1);
    for (LogicalPlan.InputPortMeta targetPort : input1.getSinks()) {
        Assert.assertEquals("tuple class name required", TestSchema.class, targetPort.getAttributes().get(PortContext.TUPLE_CLASS));
    }
}
Also used : StreamMeta(com.datatorrent.stram.plan.logical.LogicalPlan.StreamMeta) StringWriter(java.io.StringWriter) JSONObject(org.codehaus.jettison.json.JSONObject) Configuration(org.apache.hadoop.conf.Configuration) OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) InputStream(java.io.InputStream) Integer2String(com.datatorrent.api.StringCodec.Integer2String) InputPortMeta(com.datatorrent.stram.plan.logical.LogicalPlan.InputPortMeta) Test(org.junit.Test)

Example 28 with OperatorMeta

use of com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta in project apex-core by apache.

the class LogicalPlanConfigurationTest method assertNode.

private static OperatorMeta assertNode(LogicalPlan dag, String id) {
    OperatorMeta n = dag.getOperatorMeta(id);
    assertNotNull("operator exists id=" + id, n);
    return n;
}
Also used : OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta)

Example 29 with OperatorMeta

use of com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta in project apex-core by apache.

the class LogicalPlanConfigurationTest method testUnifierLevelAttributes.

@Test
@SuppressWarnings({ "UnnecessaryBoxing", "AssertEqualsBetweenInconvertibleTypes" })
public void testUnifierLevelAttributes() {
    String appName = "app1";
    final GenericTestOperator operator1 = new GenericTestOperator();
    final GenericTestOperator operator2 = new GenericTestOperator();
    StreamingApplication app = new StreamingApplication() {

        @Override
        public void populateDAG(DAG dag, Configuration conf) {
            dag.addOperator("operator1", operator1);
            dag.addOperator("operator2", operator2);
            dag.addStream("s1", operator1.outport1, operator2.inport1);
        }
    };
    Properties props = new Properties();
    props.put(StreamingApplication.APEX_PREFIX + "application." + appName + ".class", app.getClass().getName());
    props.put(StreamingApplication.APEX_PREFIX + "application." + appName + ".operator.operator1.outputport.outport1.unifier." + OperatorContext.APPLICATION_WINDOW_COUNT.getName(), "2");
    props.put(StreamingApplication.APEX_PREFIX + "application." + appName + ".operator.operator1.outputport.outport1.unifier." + OperatorContext.MEMORY_MB.getName(), "512");
    LogicalPlanConfiguration dagBuilder = new LogicalPlanConfiguration(new Configuration(false));
    dagBuilder.addFromProperties(props, null);
    String appPath = app.getClass().getName().replace(".", "/") + ".class";
    LogicalPlan dag = new LogicalPlan();
    dagBuilder.prepareDAG(dag, app, appPath);
    OperatorMeta om = null;
    for (Map.Entry<OutputPortMeta, StreamMeta> entry : dag.getOperatorMeta("operator1").getOutputStreams().entrySet()) {
        if (entry.getKey().getPortName().equals("outport1")) {
            om = entry.getKey().getUnifierMeta();
        }
    }
    Assert.assertNotNull(om);
    Assert.assertEquals("", Integer.valueOf(2), om.getValue(OperatorContext.APPLICATION_WINDOW_COUNT));
    Assert.assertEquals("", Integer.valueOf(512), om.getValue(OperatorContext.MEMORY_MB));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) Integer2String(com.datatorrent.api.StringCodec.Integer2String) StreamingApplication(com.datatorrent.api.StreamingApplication) DAG(com.datatorrent.api.DAG) Properties(java.util.Properties) StreamMeta(com.datatorrent.stram.plan.logical.LogicalPlan.StreamMeta) OutputPortMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OutputPortMeta) GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) Map(java.util.Map) AttributeMap(com.datatorrent.api.Attribute.AttributeMap) Test(org.junit.Test)

Example 30 with OperatorMeta

use of com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta in project apex-core by apache.

the class LogicalPlanConfigurationTest method testPortLevelAttributes.

@Test
@SuppressWarnings("UnnecessaryBoxing")
public void testPortLevelAttributes() {
    String appName = "app1";
    SimpleTestApplication app = new SimpleTestApplication();
    Properties props = new Properties();
    props.put(StreamingApplication.APEX_PREFIX + "application." + appName + ".class", app.getClass().getName());
    props.put(StreamingApplication.APEX_PREFIX + "application." + appName + ".operator.operator1.port.*." + PortContext.QUEUE_CAPACITY.getName(), "" + 16 * 1024);
    props.put(StreamingApplication.APEX_PREFIX + "application." + appName + ".operator.operator2.inputport.inport1." + PortContext.QUEUE_CAPACITY.getName(), "" + 32 * 1024);
    props.put(StreamingApplication.APEX_PREFIX + "application." + appName + ".operator.operator2.outputport.outport1." + PortContext.QUEUE_CAPACITY.getName(), "" + 32 * 1024);
    props.put(StreamingApplication.APEX_PREFIX + "application." + appName + ".operator.operator3.port.*." + PortContext.QUEUE_CAPACITY.getName(), "" + 16 * 1024);
    props.put(StreamingApplication.APEX_PREFIX + "application." + appName + ".operator.operator3.inputport.inport2." + PortContext.QUEUE_CAPACITY.getName(), "" + 32 * 1024);
    LogicalPlanConfiguration dagBuilder = new LogicalPlanConfiguration(new Configuration(false));
    dagBuilder.addFromProperties(props, null);
    String appPath = app.getClass().getName().replace(".", "/") + ".class";
    LogicalPlan dag = new LogicalPlan();
    dagBuilder.prepareDAG(dag, app, appPath);
    OperatorMeta om1 = dag.getOperatorMeta("operator1");
    Assert.assertEquals("", Integer.valueOf(16 * 1024), om1.getMeta(app.gt1.outport1).getValue(PortContext.QUEUE_CAPACITY));
    OperatorMeta om2 = dag.getOperatorMeta("operator2");
    Assert.assertEquals("", Integer.valueOf(32 * 1024), om2.getMeta(app.gt2.inport1).getValue(PortContext.QUEUE_CAPACITY));
    Assert.assertEquals("", Integer.valueOf(32 * 1024), om2.getMeta(app.gt2.outport1).getValue(PortContext.QUEUE_CAPACITY));
    OperatorMeta om3 = dag.getOperatorMeta("operator3");
    Assert.assertEquals("", Integer.valueOf(16 * 1024), om3.getMeta(app.gt3.inport1).getValue(PortContext.QUEUE_CAPACITY));
    Assert.assertEquals("", Integer.valueOf(32 * 1024), om3.getMeta(app.gt3.inport2).getValue(PortContext.QUEUE_CAPACITY));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) Integer2String(com.datatorrent.api.StringCodec.Integer2String) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

OperatorMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta)78 Test (org.junit.Test)38 GenericTestOperator (com.datatorrent.stram.engine.GenericTestOperator)35 Checkpoint (com.datatorrent.stram.api.Checkpoint)23 TestPlanContext (com.datatorrent.stram.plan.TestPlanContext)23 LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)23 PartitioningTest (com.datatorrent.stram.PartitioningTest)16 HashMap (java.util.HashMap)16 JSONObject (org.codehaus.jettison.json.JSONObject)16 StreamMeta (com.datatorrent.stram.plan.logical.LogicalPlan.StreamMeta)15 Map (java.util.Map)15 PTOperator (com.datatorrent.stram.plan.physical.PTOperator)14 InputPortMeta (com.datatorrent.stram.plan.logical.LogicalPlan.InputPortMeta)13 StatsListener (com.datatorrent.api.StatsListener)12 PhysicalPlan (com.datatorrent.stram.plan.physical.PhysicalPlan)12 TestGeneratorInputOperator (com.datatorrent.stram.engine.TestGeneratorInputOperator)11 Configuration (org.apache.hadoop.conf.Configuration)11 PTInput (com.datatorrent.stram.plan.physical.PTOperator.PTInput)10 Integer2String (com.datatorrent.api.StringCodec.Integer2String)9 OutputPortMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OutputPortMeta)9