apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tushargosavi <...@git.apache.org>
Subject [GitHub] incubator-apex-core pull request: APEX-103: Add module and dag int...
Date Thu, 10 Dec 2015 09:03:18 GMT
Github user tushargosavi commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-core/pull/148#discussion_r47202183
  
    --- Diff: engine/src/main/java/com/datatorrent/stram/codec/LogicalPlanSerializer.java
---
    @@ -116,91 +165,144 @@ public boolean useForType(JavaType t)
         typer = typer.inclusion(JsonTypeInfo.As.PROPERTY);
         propertyObjectMapper.setDefaultTyping(typer);
     
    -    for (OperatorMeta operatorMeta : allOperators) {
    -      HashMap<String, Object> operatorDetailMap = new HashMap<String, Object>();
    -      ArrayList<Map<String, Object>> portList = new ArrayList<Map<String,
Object>>();
    -      Map<String, Object> attributeMap = new HashMap<String, Object>();
    -
    -      String operatorName = operatorMeta.getName();
    -      operatorArray.add(operatorDetailMap);
    -      operatorDetailMap.put("name", operatorName);
    -      operatorDetailMap.put("ports", portList);
    -      operatorDetailMap.put("class", operatorMeta.getOperator().getClass().getName());
    -      operatorDetailMap.put("attributes", attributeMap);
    -      Map<Attribute<Object>, Object> rawAttributes = Attribute.AttributeMap.AttributeInitializer.getAllAttributes(operatorMeta,
Context.OperatorContext.class);
    -      for (Map.Entry<Attribute<Object>, Object> entry : rawAttributes.entrySet())
{
    -        attributeMap.put(entry.getKey().getSimpleName(), entry.getValue());
    -      }
    -
    -      ObjectMapperString str;
    +    try {
    +      str = new ObjectMapperString(propertyObjectMapper.writeValueAsString(operatorMeta.getOperator()));
    +    } catch (Throwable ex) {
    +      LOG.error("Got exception when trying to get properties for operator {}", operatorMeta.getName(),
ex);
    +      str = null;
    +    }
    +    operatorDetailMap.put("properties", str);
     
    -      try {
    -        str = new ObjectMapperString(propertyObjectMapper.writeValueAsString(operatorMeta.getOperator()));
    +    Operators.PortMappingDescriptor pmd = new Operators.PortMappingDescriptor();
    +    Operators.describe(operatorMeta.getOperator(), pmd);
    +    for (Map.Entry<String, PortContextPair<InputPort<?>>> entry : pmd.inputPorts.entrySet())
{
    +      HashMap<String, Object> portDetailMap = new HashMap<String, Object>();
    +      HashMap<String, Object> portAttributeMap = new HashMap<String, Object>();
    +      InputPortMeta portMeta = operatorMeta.getMeta(entry.getValue().component);
    +      String portName = portMeta.getPortName();
    +      portDetailMap.put("name", portName);
    +      portDetailMap.put("type", "input");
    +      portDetailMap.put("attributes", portAttributeMap);
    +      rawAttributes = Attribute.AttributeMap.AttributeInitializer.getAllAttributes(portMeta,
Context.PortContext.class);
    +      for (Map.Entry<Attribute<Object>, Object> attEntry : rawAttributes.entrySet())
{
    +        portAttributeMap.put(attEntry.getKey().getSimpleName(), attEntry.getValue());
           }
    -      catch (Throwable ex) {
    -        LOG.error("Got exception when trying to get properties for operator {}", operatorMeta.getName(),
ex);
    -        str = null;
    +      portList.add(portDetailMap);
    +    }
    +    for (Map.Entry<String, PortContextPair<OutputPort<?>>> entry :
pmd.outputPorts.entrySet()) {
    +      HashMap<String, Object> portDetailMap = new HashMap<String, Object>();
    +      HashMap<String, Object> portAttributeMap = new HashMap<String, Object>();
    +      OutputPortMeta portMeta = operatorMeta.getMeta(entry.getValue().component);
    +      String portName = portMeta.getPortName();
    +      portDetailMap.put("name", portName);
    +      portDetailMap.put("type", "output");
    +      portDetailMap.put("attributes", portAttributeMap);
    +      rawAttributes = Attribute.AttributeMap.AttributeInitializer.getAllAttributes(portMeta,
Context.PortContext.class);
    +      for (Map.Entry<Attribute<Object>, Object> attEntry : rawAttributes.entrySet())
{
    +        portAttributeMap.put(attEntry.getKey().getSimpleName(), attEntry.getValue());
           }
    -      operatorDetailMap.put("properties", str);
    -
    -      Operators.PortMappingDescriptor pmd = new Operators.PortMappingDescriptor();
    -      Operators.describe(operatorMeta.getOperator(), pmd);
    -      for (Map.Entry<String, PortContextPair<InputPort<?>>> entry :
pmd.inputPorts.entrySet()) {
    -        HashMap<String, Object> portDetailMap = new HashMap<String, Object>();
    -        HashMap<String, Object> portAttributeMap = new HashMap<String, Object>();
    -        InputPortMeta portMeta = operatorMeta.getMeta(entry.getValue().component);
    -        String portName = portMeta.getPortName();
    -        portDetailMap.put("name", portName);
    -        portDetailMap.put("type", "input");
    -        portDetailMap.put("attributes", portAttributeMap);
    -        rawAttributes = Attribute.AttributeMap.AttributeInitializer.getAllAttributes(portMeta,
Context.PortContext.class);
    -        for (Map.Entry<Attribute<Object>, Object> attEntry : rawAttributes.entrySet())
{
    -          portAttributeMap.put(attEntry.getKey().getSimpleName(), attEntry.getValue());
    -        }
    -        portList.add(portDetailMap);
    +      portList.add(portDetailMap);
    +    }
    +    return operatorDetailMap;
    +  }
    +
    +  private static Map<String, Object> getLogicalStreamDetails(StreamMeta streamMeta)
    +  {
    +
    +    HashMap<String, Object> streamDetailMap = new HashMap<String, Object>();
    +    String streamName = streamMeta.getName();
    +    String sourcePortName = streamMeta.getSource().getPortName();
    +    OperatorMeta operatorMeta = streamMeta.getSource().getOperatorMeta();
    +    HashMap<String, Object> sourcePortDetailMap = new HashMap<String, Object>();
    +    sourcePortDetailMap.put("operatorName", operatorMeta.getName());
    +    sourcePortDetailMap.put("portName", sourcePortName);
    +    streamDetailMap.put("name", streamName);
    +    streamDetailMap.put("source", sourcePortDetailMap);
    +    List<InputPortMeta> sinks = streamMeta.getSinks();
    +    ArrayList<HashMap<String, Object>> sinkPortList = new ArrayList<HashMap<String,
Object>>();
    +    for (InputPortMeta sinkPort : sinks) {
    +      HashMap<String, Object> sinkPortDetailMap = new HashMap<String, Object>();
    +      sinkPortDetailMap.put("operatorName", sinkPort.getOperatorWrapper().getName());
    +      sinkPortDetailMap.put("portName", sinkPort.getPortName());
    +      sinkPortList.add(sinkPortDetailMap);
    +    }
    +    streamDetailMap.put("sinks", sinkPortList);
    +    if (streamMeta.getLocality() != null) {
    +      streamDetailMap.put("locality", streamMeta.getLocality().name());
    +    }
    +    return streamDetailMap;
    +  }
    +
    +  /**
    +   * Return list of operators populated by module in the top level dag.
    +   * @param plan  top level dag
    +   * @param moduleMeta module.
    +   * @return
    +   */
    +  private static List<OperatorMeta> getTopLevelOperators(LogicalPlan plan, ModuleMeta
moduleMeta)
    +  {
    +    List<OperatorMeta> operators = new ArrayList<OperatorMeta>();
    +    for (OperatorMeta oMeta : moduleMeta.getDag().getAllOperators()) {
    +      if (oMeta.getModuleName() == null) {
    +        String fullName = moduleMeta.getFullName() + LogicalPlan.MODULE_NAMESPACE_SEPARATOR
+ oMeta.getName();
    +        OperatorMeta meta = plan.getOperatorMeta(fullName);
    +        operators.add(meta);
           }
    -      for (Map.Entry<String, PortContextPair<OutputPort<?>>> entry
: pmd.outputPorts.entrySet()) {
    -        HashMap<String, Object> portDetailMap = new HashMap<String, Object>();
    -        HashMap<String, Object> portAttributeMap = new HashMap<String, Object>();
    -        OutputPortMeta portMeta = operatorMeta.getMeta(entry.getValue().component);
    -        String portName = portMeta.getPortName();
    -        portDetailMap.put("name", portName);
    -        portDetailMap.put("type", "output");
    -        portDetailMap.put("attributes", portAttributeMap);
    -        rawAttributes = Attribute.AttributeMap.AttributeInitializer.getAllAttributes(portMeta,
Context.PortContext.class);
    -        for (Map.Entry<Attribute<Object>, Object> attEntry : rawAttributes.entrySet())
{
    -          portAttributeMap.put(attEntry.getKey().getSimpleName(), attEntry.getValue());
    -        }
    -        portList.add(portDetailMap);
    +    }
    +    return operators;
    +  }
    +
    +  /**
    +   * Return list of streams populated by module in top level dag.
    +   * @param plan top level dag
    +   * @param moduleMeta module
    +   * @return
    +   */
    +  private static List<StreamMeta> getTopLevelStreams(LogicalPlan plan, ModuleMeta
moduleMeta)
    +  {
    +    List<StreamMeta> streams = new ArrayList<StreamMeta>();
    +    for (StreamMeta sMeta : moduleMeta.getDag().getAllStreams()) {
    +      if (sMeta.getModuleName() == null) {
    +        String fullName = moduleMeta.getFullName() + LogicalPlan.MODULE_NAMESPACE_SEPARATOR
+ sMeta.getName();
    +        StreamMeta meta = plan.getStream(fullName);
    +        streams.add(meta);
           }
         }
    -    Collection<StreamMeta> allStreams = dag.getAllStreams();
    +    return streams;
    +  }
     
    -    for (StreamMeta streamMeta : allStreams) {
    -      HashMap<String, Object> streamDetailMap = new HashMap<String, Object>();
    -      String streamName = streamMeta.getName();
    -      streamMap.add(streamDetailMap);
    -      String sourcePortName = streamMeta.getSource().getPortName();
    -      OperatorMeta operatorMeta = streamMeta.getSource().getOperatorMeta();
    -      HashMap<String, Object> sourcePortDetailMap = new HashMap<String, Object>();
    -      sourcePortDetailMap.put("operatorName", operatorMeta.getName());
    -      sourcePortDetailMap.put("portName", sourcePortName);
    -      streamDetailMap.put("name", streamName);
    -      streamDetailMap.put("source", sourcePortDetailMap);
    -      List<InputPortMeta> sinks = streamMeta.getSinks();
    -      ArrayList<HashMap<String, Object>> sinkPortList = new ArrayList<HashMap<String,
Object>>();
    -      for (InputPortMeta sinkPort : sinks) {
    -        HashMap<String, Object> sinkPortDetailMap = new HashMap<String, Object>();
    -        sinkPortDetailMap.put("operatorName", sinkPort.getOperatorWrapper().getName());
    -        sinkPortDetailMap.put("portName", sinkPort.getPortName());
    -        sinkPortList.add(sinkPortDetailMap);
    +  private static List<Map<String, Object>> getLogicalModulesInfo(LogicalPlan
dag, boolean flatten)
    +  {
    +    List<Map<String, Object>> modulesArray = new ArrayList<Map<String,
Object>>();
    +    for (ModuleMeta moduleMeta : dag.getAllModules()) {
    +      modulesArray.add(fillLogicalModuleDetails(dag, moduleMeta, flatten));
    +    }
    +    return modulesArray;
    +  }
    +
    +  private static Map<String, Object> fillLogicalModuleDetails(LogicalPlan dag,
ModuleMeta moduleMeta, boolean flatten)
    +  {
    +    Map<String, Object> moduleDetailMap = new HashMap<String, Object>();
    +    ArrayList<Map<String, Object>> operatorArray = new ArrayList<Map<String,
Object>>();
    +    ArrayList<Map<String, Object>> streamArray = new ArrayList<Map<String,
Object>>();
    +    moduleDetailMap.put("name", moduleMeta.getName());
    +    moduleDetailMap.put("className", moduleMeta.getModule().getClass().getName());
    +    if (flatten) {
    +      moduleDetailMap.put("operators", operatorArray);
    +      for (OperatorMeta operatorMeta : getTopLevelOperators(dag, moduleMeta)) {
    +        operatorArray.add(getLogicalOperatorDetails(operatorMeta));
           }
    -      streamDetailMap.put("sinks", sinkPortList);
    -      if (streamMeta.getLocality() != null) {
    -        streamDetailMap.put("locality", streamMeta.getLocality().name());
    +      moduleDetailMap.put("streams", streamArray);
    +      for (StreamMeta streamMeta : getTopLevelStreams(dag, moduleMeta)) {
    --- End diff --
    
    Same as above, Module has operator, stream connecting internal operators and other modules.
and internal modules. This method goes over all three entities for building response.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message