Search in sources :

Example 36 with OperatorMeta

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

the class StreamingContainerManagerTest method testValidGenericOperatorDeployInfoType.

@Test
public void testValidGenericOperatorDeployInfoType() {
    GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
    TestGeneratorInputOperator.ValidGenericOperator o2 = dag.addOperator("o2", TestGeneratorInputOperator.ValidGenericOperator.class);
    dag.addStream("stream1", o1.outport1, o2.input);
    dag.setAttribute(OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
    StreamingContainerManager scm = new StreamingContainerManager(dag);
    PhysicalPlan physicalPlan = scm.getPhysicalPlan();
    List<PTContainer> containers = physicalPlan.getContainers();
    for (int i = 0; i < containers.size(); ++i) {
        assignContainer(scm, "container" + (i + 1));
    }
    OperatorMeta o2Meta = dag.getMeta(o2);
    PTOperator o2Physical = physicalPlan.getOperators(o2Meta).get(0);
    String containerId = o2Physical.getContainer().getExternalId();
    OperatorDeployInfo o1DeployInfo = getDeployInfo(scm.getContainerAgent(containerId)).get(0);
    Assert.assertEquals("type " + o1DeployInfo, OperatorDeployInfo.OperatorType.GENERIC, o1DeployInfo.type);
}
Also used : PhysicalPlan(com.datatorrent.stram.plan.physical.PhysicalPlan) OperatorDeployInfo(com.datatorrent.stram.api.OperatorDeployInfo) OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) PTOperator(com.datatorrent.stram.plan.physical.PTOperator) TestGeneratorInputOperator(com.datatorrent.stram.engine.TestGeneratorInputOperator) Checkpoint(com.datatorrent.stram.api.Checkpoint) GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) MemoryStorageAgent(com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent) PTContainer(com.datatorrent.stram.plan.physical.PTContainer) Test(org.junit.Test) PhysicalPlanTest(com.datatorrent.stram.plan.physical.PhysicalPlanTest)

Example 37 with OperatorMeta

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

the class StramWebServices method getPortAttributes.

@GET
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/ports/{portName}/attributes")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getPortAttributes(@PathParam("operatorName") String operatorName, @PathParam("portName") String portName, @QueryParam("attributeName") String attributeName) {
    init();
    OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
    if (logicalOperator == null) {
        throw new NotFoundException();
    }
    HashMap<String, String> map = new HashMap<>();
    for (Map.Entry<Attribute<?>, Object> entry : dagManager.getPortAttributes(operatorName, portName).entrySet()) {
        if (attributeName == null || entry.getKey().getSimpleName().equals(attributeName)) {
            Map.Entry<Attribute<Object>, Object> entry1 = (Map.Entry<Attribute<Object>, Object>) (Map.Entry) entry;
            map.put(entry1.getKey().getSimpleName(), entry1.getKey().codec.toString(entry1.getValue()));
        }
    }
    return new JSONObject(map);
}
Also used : OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) JSONObject(org.codehaus.jettison.json.JSONObject) HashMap(java.util.HashMap) Attribute(com.datatorrent.api.Attribute) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) JSONObject(org.codehaus.jettison.json.JSONObject) Map(java.util.Map) BeanMap(org.apache.commons.beanutils.BeanMap) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 38 with OperatorMeta

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

the class StramWebServices method getOperatorAggregation.

@GET
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/aggregation")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getOperatorAggregation(@PathParam("operatorName") String operatorName) throws Exception {
    init();
    OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
    if (logicalOperator == null) {
        throw new NotFoundException();
    }
    OperatorAggregationInfo operatorAggregationInfo = dagManager.getOperatorAggregationInfo(operatorName);
    return new JSONObject(objectMapper.writeValueAsString(operatorAggregationInfo));
}
Also used : OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) JSONObject(org.codehaus.jettison.json.JSONObject) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 39 with OperatorMeta

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

the class StramWebServices method getPort.

@GET
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/ports/{portName}")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getPort(@PathParam("operatorName") String operatorName, @PathParam("portName") String portName) {
    init();
    OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
    Set<LogicalPlan.InputPortMeta> inputPorts;
    Set<LogicalPlan.OutputPortMeta> outputPorts;
    if (logicalOperator == null) {
        ModuleMeta logicalModule = dagManager.getModuleMeta(operatorName);
        if (logicalModule == null) {
            throw new NotFoundException();
        }
        inputPorts = logicalModule.getInputStreams().keySet();
        outputPorts = logicalModule.getOutputStreams().keySet();
    } else {
        inputPorts = logicalOperator.getInputStreams().keySet();
        outputPorts = logicalOperator.getOutputStreams().keySet();
    }
    try {
        JSONObject resp = getPortObject(inputPorts, outputPorts, portName);
        if (resp != null) {
            return resp;
        }
    } catch (JSONException ex) {
        throw new RuntimeException(ex);
    }
    throw new NotFoundException();
}
Also used : ModuleMeta(com.datatorrent.stram.plan.logical.LogicalPlan.ModuleMeta) OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) JSONObject(org.codehaus.jettison.json.JSONObject) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) JSONException(org.codehaus.jettison.json.JSONException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 40 with OperatorMeta

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

the class StramWebServices method setOperatorProperties.

// not supported by WebAppProxyServlet, can only be called directly
@POST
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/properties")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject setOperatorProperties(JSONObject request, @PathParam("operatorName") String operatorName) {
    init();
    OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
    if (logicalOperator == null) {
        throw new NotFoundException();
    }
    JSONObject response = new JSONObject();
    try {
        @SuppressWarnings("unchecked") Iterator<String> keys = request.keys();
        while (keys.hasNext()) {
            String key = keys.next();
            String val = request.isNull(key) ? null : request.getString(key);
            LOG.debug("Setting property for {}: {}={}", operatorName, key, val);
            dagManager.setOperatorProperty(operatorName, key, val);
        }
    } catch (JSONException ex) {
        LOG.warn("Got JSON Exception: ", ex);
    } catch (Exception ex) {
        LOG.error("Caught exception: ", ex);
        throw new RuntimeException(ex);
    }
    return response;
}
Also used : OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) JSONObject(org.codehaus.jettison.json.JSONObject) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) JSONException(org.codehaus.jettison.json.JSONException) TimeoutException(java.util.concurrent.TimeoutException) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.codehaus.jettison.json.JSONException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

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