Github user tweise commented on a diff in the pull request:
https://github.com/apache/incubator-apex-core/pull/148#discussion_r47925289
--- Diff:
engine/src/main/java/com/datatorrent/stram/codec/LogicalPlanSerializer.java ---
@@ -116,91 +172,110 @@ 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()));
- }
- catch (Throwable ex) {
- LOG.error("Got exception when trying to get properties for
operator {}", operatorMeta.getName(), ex);
- str = null;
- }
- 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);
+ 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());
}
- 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);
+ 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());
}
+ portList.add(portDetailMap);
}
- Collection<StreamMeta> allStreams = dag.getAllStreams();
+ return operatorDetailMap;
+ }
- 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 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 information about module and sub-dag populated by it.
+ *
+ * @param dag top level DAG
+ * @param moduleMeta module information. DAG within module is used for
constructing response.
+ * @return
+ */
+ private static Map<String, Object> getLogicalModuleDetails(LogicalPlan
dag, ModuleMeta moduleMeta)
+ {
+ 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());
+
+ moduleDetailMap.put("operators", operatorArray);
+ for (OperatorMeta operatorMeta :
moduleMeta.getDag().getAllOperators()) {
+ if (operatorMeta.getModuleName() == null) {
+ String fullName = moduleMeta.getFullName() +
LogicalPlan.MODULE_NAMESPACE_SEPARATOR + operatorMeta.getName();
+
operatorArray.add(getLogicalOperatorDetails(dag.getOperatorMeta(fullName)));
}
- streamDetailMap.put("sinks", sinkPortList);
- if (streamMeta.getLocality() != null) {
- streamDetailMap.put("locality", streamMeta.getLocality().name());
+ }
+ moduleDetailMap.put("streams", streamArray);
+ for (StreamMeta sMeta : moduleMeta.getDag().getAllStreams()) {
+ if (sMeta.getModuleName() == null) {
+ String fullName = moduleMeta.getFullName() +
LogicalPlan.MODULE_NAMESPACE_SEPARATOR + sMeta.getName();
+ streamArray.add(getLogicalStreamDetails(dag.getStream(fullName)));
}
}
- return result;
--- End diff --
For every module, it is sufficient to include the operator names and
submodules. Everything else can be derived from the flattened DAG.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---