Repository: incubator-apex-core Updated Branches: refs/heads/master 2ad07ee1a -> 228c795d5
APEXCORE-451 : get-app-package-operators in ApexCLI to contain "type" property to indicate operator or module Project: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/commit/41666de8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/tree/41666de8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/diff/41666de8 Branch: refs/heads/master Commit: 41666de8e95a3a580578f08b3e7ed68ddcde0a7b Parents: da46ec1 Author: shubham <shubham-patha...@github.com> Authored: Thu May 5 15:19:48 2016 +0530 Committer: shubham <shubham-patha...@github.com> Committed: Fri May 6 11:20:53 2016 +0530 ---------------------------------------------------------------------- .../java/com/datatorrent/stram/cli/ApexCli.java | 3 +- .../stram/webapp/OperatorDiscoverer.java | 40 +++++++++++++++++--- .../com/datatorrent/stram/webapp/TypeGraph.java | 5 ++- 3 files changed, 39 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/41666de8/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java ---------------------------------------------------------------------- diff --git a/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java b/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java index 67406a3..4e1f201 100644 --- a/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java +++ b/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java @@ -93,6 +93,7 @@ import com.google.common.collect.Sets; import com.sun.jersey.api.client.WebResource; import com.datatorrent.api.Context; +import com.datatorrent.api.DAG.GenericOperator; import com.datatorrent.api.Operator; import com.datatorrent.api.StreamingApplication; import com.datatorrent.stram.StramClient; @@ -2963,7 +2964,7 @@ public class ApexCli String[] newArgs = new String[args.length - 1]; System.arraycopy(args, 1, newArgs, 0, args.length - 1); GetOperatorClassesCommandLineInfo commandLineInfo = getGetOperatorClassesCommandLineInfo(newArgs); - String parentName = commandLineInfo.parent != null ? commandLineInfo.parent : Operator.class.getName(); + String parentName = commandLineInfo.parent != null ? commandLineInfo.parent : GenericOperator.class.getName(); String files = expandCommaSeparatedFiles(commandLineInfo.args[0]); if (files == null) { throw new CliException("File " + commandLineInfo.args[0] + " is not found"); http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/41666de8/engine/src/main/java/com/datatorrent/stram/webapp/OperatorDiscoverer.java ---------------------------------------------------------------------- diff --git a/engine/src/main/java/com/datatorrent/stram/webapp/OperatorDiscoverer.java b/engine/src/main/java/com/datatorrent/stram/webapp/OperatorDiscoverer.java index 8aa2c20..c388a19 100644 --- a/engine/src/main/java/com/datatorrent/stram/webapp/OperatorDiscoverer.java +++ b/engine/src/main/java/com/datatorrent/stram/webapp/OperatorDiscoverer.java @@ -68,6 +68,8 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import com.datatorrent.api.DAG.GenericOperator; +import com.datatorrent.api.Module; import com.datatorrent.api.Operator; import com.datatorrent.stram.util.ObjectMapperFactory; import com.datatorrent.stram.webapp.TypeDiscoverer.UI_TYPE; @@ -116,6 +118,22 @@ public class OperatorDiscoverer boolean omitFromUI; } + enum GenericOperatorType + { + OPERATOR("operator"), MODULE("module"); + private final String type; + + private GenericOperatorType(String type) + { + this.type = type; + } + + public String getType() + { + return type; + } + } + enum MethodTagType { USE_SCHEMA("@useSchema"), @@ -301,9 +319,9 @@ public class OperatorDiscoverer public void addDefaultValue(String className, JSONObject oper) throws Exception { ObjectMapper defaultValueMapper = ObjectMapperFactory.getOperatorValueSerializer(); - Class<? extends Operator> clazz = (Class<? extends Operator>)classLoader.loadClass(className); + Class<? extends GenericOperator> clazz = (Class<? extends GenericOperator>)classLoader.loadClass(className); if (clazz != null) { - Operator operIns = clazz.newInstance(); + GenericOperator operIns = clazz.newInstance(); String s = defaultValueMapper.writeValueAsString(operIns); oper.put("defaultValue", new JSONObject(s).get(className)); } @@ -405,9 +423,9 @@ public class OperatorDiscoverer loadOperatorClass(); } if (parent == null) { - parent = Operator.class.getName(); + parent = GenericOperator.class.getName(); } else { - if (!typeGraph.isAncestor(Operator.class.getName(), parent)) { + if (!typeGraph.isAncestor(GenericOperator.class.getName(), parent)) { throw new IllegalArgumentException("Argument must be a subclass of Operator class"); } } @@ -422,7 +440,7 @@ public class OperatorDiscoverer } }); - if (searchTerm == null && parent.equals(Operator.class.getName())) { + if (searchTerm == null && parent.equals(GenericOperator.class.getName())) { return filteredClass; } @@ -432,7 +450,7 @@ public class OperatorDiscoverer Set<String> result = new HashSet<>(); for (String clazz : filteredClass) { - if (parent.equals(Operator.class.getName()) || typeGraph.isAncestor(parent, clazz)) { + if (parent.equals(GenericOperator.class.getName()) || typeGraph.isAncestor(parent, clazz)) { if (searchTerm == null) { result.add(clazz); } else { @@ -526,6 +544,16 @@ public class OperatorDiscoverer response.put(PORT_TYPE_INFO_KEY, portTypeInfo); response.put("inputPorts", inputPorts); response.put("outputPorts", outputPorts); + String type = null; + Class<?> genericOperator = classLoader.loadClass(clazz); + if (Module.class.isAssignableFrom(genericOperator)) { + type = GenericOperatorType.MODULE.getType(); + } else if (Operator.class.isAssignableFrom(genericOperator)) { + type = GenericOperatorType.OPERATOR.getType(); + } + if (type != null) { + response.put("type", type); + } OperatorClassInfo oci = classInfo.get(clazz); http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/41666de8/engine/src/main/java/com/datatorrent/stram/webapp/TypeGraph.java ---------------------------------------------------------------------- diff --git a/engine/src/main/java/com/datatorrent/stram/webapp/TypeGraph.java b/engine/src/main/java/com/datatorrent/stram/webapp/TypeGraph.java index 2f91b11..e50cb77 100644 --- a/engine/src/main/java/com/datatorrent/stram/webapp/TypeGraph.java +++ b/engine/src/main/java/com/datatorrent/stram/webapp/TypeGraph.java @@ -64,6 +64,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.primitives.Primitives; import com.datatorrent.api.Component; +import com.datatorrent.api.DAG.GenericOperator; import com.datatorrent.api.InputOperator; import com.datatorrent.api.Operator; import com.datatorrent.common.util.BaseOperator; @@ -348,7 +349,7 @@ public class TypeGraph public Set<String> getAllDTInstantiableOperators() { - TypeGraphVertex tgv = typeGraph.get(Operator.class.getName()); + TypeGraphVertex tgv = typeGraph.get(GenericOperator.class.getName()); if (tgv == null) { return null; } @@ -603,7 +604,7 @@ public class TypeGraph this.classNode = ccn; // update the port information if it is a Operator - if (owner.isAncestor(Operator.class.getName(), typeName)) { + if (owner.isAncestor(GenericOperator.class.getName(), typeName)) { // load ports if it is an Operator class CompactUtil.updateCompactClassPortInfo(classN, ccn); List<CompactFieldNode> prunedFields = new LinkedList<>();