List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeHtml4
public static final String escapeHtml4(final String input)
Escapes the characters in a String using HTML entities.
For example:
"bread" & "butter"
"bread" & "butter"
.
From source file:org.apache.flink.compiler.plandump.PlanJSONDumpGenerator.java
private boolean visit(DumpableNode<?> node, PrintWriter writer, boolean first) { // check for duplicate traversal if (this.nodeIds.containsKey(node)) { return false; }// w w w . j av a 2 s . c o m // assign an id first this.nodeIds.put(node, this.nodeCnt++); // then recurse for (DumpableNode<?> child : node.getPredecessors()) { //This is important, because when the node was already in the graph it is not allowed //to set first to false! if (visit(child, writer, first)) { first = false; } ; } // check if this node should be skipped from the dump final OptimizerNode n = node.getOptimizerNode(); // ------------------ dump after the ascend --------------------- // start a new node and output node id if (!first) { writer.print(",\n"); } // open the node writer.print("\t{\n"); // recurse, it is is an iteration node if (node instanceof BulkIterationNode || node instanceof BulkIterationPlanNode) { DumpableNode<?> innerChild = node instanceof BulkIterationNode ? ((BulkIterationNode) node).getNextPartialSolution() : ((BulkIterationPlanNode) node).getRootOfStepFunction(); DumpableNode<?> begin = node instanceof BulkIterationNode ? ((BulkIterationNode) node).getPartialSolution() : ((BulkIterationPlanNode) node).getPartialSolutionPlanNode(); writer.print("\t\t\"step_function\": [\n"); visit(innerChild, writer, true); writer.print("\n\t\t],\n"); writer.print("\t\t\"partial_solution\": " + this.nodeIds.get(begin) + ",\n"); writer.print("\t\t\"next_partial_solution\": " + this.nodeIds.get(innerChild) + ",\n"); } else if (node instanceof WorksetIterationNode || node instanceof WorksetIterationPlanNode) { DumpableNode<?> worksetRoot = node instanceof WorksetIterationNode ? ((WorksetIterationNode) node).getNextWorkset() : ((WorksetIterationPlanNode) node).getNextWorkSetPlanNode(); DumpableNode<?> solutionDelta = node instanceof WorksetIterationNode ? ((WorksetIterationNode) node).getSolutionSetDelta() : ((WorksetIterationPlanNode) node).getSolutionSetDeltaPlanNode(); DumpableNode<?> workset = node instanceof WorksetIterationNode ? ((WorksetIterationNode) node).getWorksetNode() : ((WorksetIterationPlanNode) node).getWorksetPlanNode(); DumpableNode<?> solutionSet = node instanceof WorksetIterationNode ? ((WorksetIterationNode) node).getSolutionSetNode() : ((WorksetIterationPlanNode) node).getSolutionSetPlanNode(); writer.print("\t\t\"step_function\": [\n"); visit(worksetRoot, writer, true); visit(solutionDelta, writer, false); writer.print("\n\t\t],\n"); writer.print("\t\t\"workset\": " + this.nodeIds.get(workset) + ",\n"); writer.print("\t\t\"solution_set\": " + this.nodeIds.get(solutionSet) + ",\n"); writer.print("\t\t\"next_workset\": " + this.nodeIds.get(worksetRoot) + ",\n"); writer.print("\t\t\"solution_delta\": " + this.nodeIds.get(solutionDelta) + ",\n"); } // print the id writer.print("\t\t\"id\": " + this.nodeIds.get(node)); final String type; String contents; if (n instanceof DataSinkNode) { type = "sink"; contents = n.getPactContract().toString(); } else if (n instanceof DataSourceNode) { type = "source"; contents = n.getPactContract().toString(); } else if (n instanceof BulkIterationNode) { type = "bulk_iteration"; contents = n.getPactContract().getName(); } else if (n instanceof WorksetIterationNode) { type = "workset_iteration"; contents = n.getPactContract().getName(); } else if (n instanceof BinaryUnionNode) { type = "pact"; contents = ""; } else { type = "pact"; contents = n.getPactContract().getName(); } contents = StringUtils.showControlCharacters(contents); if (encodeForHTML) { contents = StringEscapeUtils.escapeHtml4(contents); contents = contents.replace("\\", "\"); } String name = n.getName(); if (name.equals("Reduce") && (node instanceof SingleInputPlanNode) && ((SingleInputPlanNode) node).getDriverStrategy() == DriverStrategy.SORTED_GROUP_COMBINE) { name = "Combine"; } // output the type identifier writer.print(",\n\t\t\"type\": \"" + type + "\""); // output node name writer.print(",\n\t\t\"pact\": \"" + name + "\""); // output node contents writer.print(",\n\t\t\"contents\": \"" + contents + "\""); // degree of parallelism writer.print(",\n\t\t\"parallelism\": \"" + (n.getDegreeOfParallelism() >= 1 ? n.getDegreeOfParallelism() : "default") + "\""); // output node predecessors Iterator<? extends DumpableConnection<?>> inConns = node.getDumpableInputs().iterator(); String child1name = "", child2name = ""; if (inConns != null && inConns.hasNext()) { // start predecessor list writer.print(",\n\t\t\"predecessors\": ["); int inputNum = 0; while (inConns.hasNext()) { final DumpableConnection<?> inConn = inConns.next(); final DumpableNode<?> source = inConn.getSource(); writer.print(inputNum == 0 ? "\n" : ",\n"); if (inputNum == 0) { child1name += child1name.length() > 0 ? ", " : ""; child1name += source.getOptimizerNode().getPactContract().getName(); } else if (inputNum == 1) { child2name += child2name.length() > 0 ? ", " : ""; child2name = source.getOptimizerNode().getPactContract().getName(); } // output predecessor id writer.print("\t\t\t{\"id\": " + this.nodeIds.get(source)); // output connection side if (inConns.hasNext() || inputNum > 0) { writer.print(", \"side\": \"" + (inputNum == 0 ? "first" : "second") + "\""); } // output shipping strategy and channel type final Channel channel = (inConn instanceof Channel) ? (Channel) inConn : null; final ShipStrategyType shipType = channel != null ? channel.getShipStrategy() : ((PactConnection) inConn).getShipStrategy(); String shipStrategy = null; if (shipType != null) { switch (shipType) { case NONE: // nothing break; case FORWARD: shipStrategy = "Forward"; break; case BROADCAST: shipStrategy = "Broadcast"; break; case PARTITION_HASH: shipStrategy = "Hash Partition"; break; case PARTITION_RANGE: shipStrategy = "Range Partition"; break; case PARTITION_RANDOM: shipStrategy = "Redistribute"; break; case PARTITION_FORCED_REBALANCE: shipStrategy = "Rebalance"; break; case PARTITION_CUSTOM: shipStrategy = "Custom Partition"; break; default: throw new CompilerException("Unknown ship strategy '" + inConn.getShipStrategy().name() + "' in JSON generator."); } } if (channel != null && channel.getShipStrategyKeys() != null && channel.getShipStrategyKeys().size() > 0) { shipStrategy += " on " + (channel.getShipStrategySortOrder() == null ? channel.getShipStrategyKeys().toString() : Utils.createOrdering(channel.getShipStrategyKeys(), channel.getShipStrategySortOrder()).toString()); } if (shipStrategy != null) { writer.print(", \"ship_strategy\": \"" + shipStrategy + "\""); } if (channel != null) { String localStrategy = null; switch (channel.getLocalStrategy()) { case NONE: break; case SORT: localStrategy = "Sort"; break; case COMBININGSORT: localStrategy = "Sort (combining)"; break; default: throw new CompilerException("Unknown local strategy " + channel.getLocalStrategy().name()); } if (channel != null && channel.getLocalStrategyKeys() != null && channel.getLocalStrategyKeys().size() > 0) { localStrategy += " on " + (channel.getLocalStrategySortOrder() == null ? channel.getLocalStrategyKeys().toString() : Utils.createOrdering(channel.getLocalStrategyKeys(), channel.getLocalStrategySortOrder()).toString()); } if (localStrategy != null) { writer.print(", \"local_strategy\": \"" + localStrategy + "\""); } if (channel != null && channel.getTempMode() != TempMode.NONE) { String tempMode = channel.getTempMode().toString(); writer.print(", \"temp_mode\": \"" + tempMode + "\""); } } writer.print('}'); inputNum++; } // finish predecessors writer.print("\n\t\t]"); } //--------------------------------------------------------------------------------------- // the part below here is relevant only to plan nodes with concrete strategies, etc //--------------------------------------------------------------------------------------- final PlanNode p = node.getPlanNode(); if (p == null) { // finish node writer.print("\n\t}"); return true; } // local strategy String locString = null; if (p.getDriverStrategy() != null) { switch (p.getDriverStrategy()) { case NONE: case BINARY_NO_OP: break; case UNARY_NO_OP: locString = "No-Op"; break; case COLLECTOR_MAP: case MAP: locString = "Map"; break; case FLAT_MAP: locString = "FlatMap"; break; case MAP_PARTITION: locString = "Map Partition"; break; case ALL_REDUCE: locString = "Reduce All"; break; case ALL_GROUP_REDUCE: case ALL_GROUP_COMBINE: locString = "Group Reduce All"; break; case SORTED_REDUCE: locString = "Sorted Reduce"; break; case SORTED_PARTIAL_REDUCE: locString = "Sorted Combine/Reduce"; break; case SORTED_GROUP_REDUCE: locString = "Sorted Group Reduce"; break; case SORTED_GROUP_COMBINE: locString = "Sorted Combine"; break; case HYBRIDHASH_BUILD_FIRST: locString = "Hybrid Hash (build: " + child1name + ")"; break; case HYBRIDHASH_BUILD_SECOND: locString = "Hybrid Hash (build: " + child2name + ")"; break; case HYBRIDHASH_BUILD_FIRST_CACHED: locString = "Hybrid Hash (CACHED) (build: " + child1name + ")"; break; case HYBRIDHASH_BUILD_SECOND_CACHED: locString = "Hybrid Hash (CACHED) (build: " + child2name + ")"; break; case NESTEDLOOP_BLOCKED_OUTER_FIRST: locString = "Nested Loops (Blocked Outer: " + child1name + ")"; break; case NESTEDLOOP_BLOCKED_OUTER_SECOND: locString = "Nested Loops (Blocked Outer: " + child2name + ")"; break; case NESTEDLOOP_STREAMED_OUTER_FIRST: locString = "Nested Loops (Streamed Outer: " + child1name + ")"; break; case NESTEDLOOP_STREAMED_OUTER_SECOND: locString = "Nested Loops (Streamed Outer: " + child2name + ")"; break; case MERGE: locString = "Merge"; break; case CO_GROUP: locString = "Co-Group"; break; default: locString = p.getDriverStrategy().name(); break; } if (locString != null) { writer.print(",\n\t\t\"driver_strategy\": \""); writer.print(locString); writer.print("\""); } } { // output node global properties final GlobalProperties gp = p.getGlobalProperties(); writer.print(",\n\t\t\"global_properties\": [\n"); addProperty(writer, "Partitioning", gp.getPartitioning().name(), true); if (gp.getPartitioningFields() != null) { addProperty(writer, "Partitioned on", gp.getPartitioningFields().toString(), false); } if (gp.getPartitioningOrdering() != null) { addProperty(writer, "Partitioning Order", gp.getPartitioningOrdering().toString(), false); } else { addProperty(writer, "Partitioning Order", "(none)", false); } if (n.getUniqueFields() == null || n.getUniqueFields().size() == 0) { addProperty(writer, "Uniqueness", "not unique", false); } else { addProperty(writer, "Uniqueness", n.getUniqueFields().toString(), false); } writer.print("\n\t\t]"); } { // output node local properties LocalProperties lp = p.getLocalProperties(); writer.print(",\n\t\t\"local_properties\": [\n"); if (lp.getOrdering() != null) { addProperty(writer, "Order", lp.getOrdering().toString(), true); } else { addProperty(writer, "Order", "(none)", true); } if (lp.getGroupedFields() != null && lp.getGroupedFields().size() > 0) { addProperty(writer, "Grouped on", lp.getGroupedFields().toString(), false); } else { addProperty(writer, "Grouping", "not grouped", false); } if (n.getUniqueFields() == null || n.getUniqueFields().size() == 0) { addProperty(writer, "Uniqueness", "not unique", false); } else { addProperty(writer, "Uniqueness", n.getUniqueFields().toString(), false); } writer.print("\n\t\t]"); } // output node size estimates writer.print(",\n\t\t\"estimates\": [\n"); addProperty(writer, "Est. Output Size", n.getEstimatedOutputSize() == -1 ? "(unknown)" : formatNumber(n.getEstimatedOutputSize(), "B"), true); addProperty(writer, "Est. Cardinality", n.getEstimatedNumRecords() == -1 ? "(unknown)" : formatNumber(n.getEstimatedNumRecords()), false); writer.print("\t\t]"); // output node cost if (p.getNodeCosts() != null) { writer.print(",\n\t\t\"costs\": [\n"); addProperty(writer, "Network", p.getNodeCosts().getNetworkCost() == -1 ? "(unknown)" : formatNumber(p.getNodeCosts().getNetworkCost(), "B"), true); addProperty(writer, "Disk I/O", p.getNodeCosts().getDiskCost() == -1 ? "(unknown)" : formatNumber(p.getNodeCosts().getDiskCost(), "B"), false); addProperty(writer, "CPU", p.getNodeCosts().getCpuCost() == -1 ? "(unknown)" : formatNumber(p.getNodeCosts().getCpuCost(), ""), false); addProperty(writer, "Cumulative Network", p.getCumulativeCosts().getNetworkCost() == -1 ? "(unknown)" : formatNumber(p.getCumulativeCosts().getNetworkCost(), "B"), false); addProperty(writer, "Cumulative Disk I/O", p.getCumulativeCosts().getDiskCost() == -1 ? "(unknown)" : formatNumber(p.getCumulativeCosts().getDiskCost(), "B"), false); addProperty(writer, "Cumulative CPU", p.getCumulativeCosts().getCpuCost() == -1 ? "(unknown)" : formatNumber(p.getCumulativeCosts().getCpuCost(), ""), false); writer.print("\n\t\t]"); } // output the node compiler hints if (n.getPactContract().getCompilerHints() != null) { CompilerHints hints = n.getPactContract().getCompilerHints(); CompilerHints defaults = new CompilerHints(); String size = hints.getOutputSize() == defaults.getOutputSize() ? "(none)" : String.valueOf(hints.getOutputSize()); String card = hints.getOutputCardinality() == defaults.getOutputCardinality() ? "(none)" : String.valueOf(hints.getOutputCardinality()); String width = hints.getAvgOutputRecordSize() == defaults.getAvgOutputRecordSize() ? "(none)" : String.valueOf(hints.getAvgOutputRecordSize()); String filter = hints.getFilterFactor() == defaults.getFilterFactor() ? "(none)" : String.valueOf(hints.getFilterFactor()); writer.print(",\n\t\t\"compiler_hints\": [\n"); addProperty(writer, "Output Size (bytes)", size, true); addProperty(writer, "Output Cardinality", card, false); addProperty(writer, "Avg. Output Record Size (bytes)", width, false); addProperty(writer, "Filter Factor", filter, false); writer.print("\t\t]"); } // finish node writer.print("\n\t}"); return true; }
From source file:org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator.java
private boolean visit(DumpableNode<?> node, PrintWriter writer, boolean first) { // check for duplicate traversal if (this.nodeIds.containsKey(node)) { return false; }/*from ww w . ja va 2s. c o m*/ // assign an id first this.nodeIds.put(node, this.nodeCnt++); // then recurse for (DumpableNode<?> child : node.getPredecessors()) { //This is important, because when the node was already in the graph it is not allowed //to set first to false! if (visit(child, writer, first)) { first = false; } } // check if this node should be skipped from the dump final OptimizerNode n = node.getOptimizerNode(); // ------------------ dump after the ascend --------------------- // start a new node and output node id if (!first) { writer.print(",\n"); } // open the node writer.print("\t{\n"); // recurse, it is is an iteration node if (node instanceof BulkIterationNode || node instanceof BulkIterationPlanNode) { DumpableNode<?> innerChild = node instanceof BulkIterationNode ? ((BulkIterationNode) node).getNextPartialSolution() : ((BulkIterationPlanNode) node).getRootOfStepFunction(); DumpableNode<?> begin = node instanceof BulkIterationNode ? ((BulkIterationNode) node).getPartialSolution() : ((BulkIterationPlanNode) node).getPartialSolutionPlanNode(); writer.print("\t\t\"step_function\": [\n"); visit(innerChild, writer, true); writer.print("\n\t\t],\n"); writer.print("\t\t\"partial_solution\": " + this.nodeIds.get(begin) + ",\n"); writer.print("\t\t\"next_partial_solution\": " + this.nodeIds.get(innerChild) + ",\n"); } else if (node instanceof WorksetIterationNode || node instanceof WorksetIterationPlanNode) { DumpableNode<?> worksetRoot = node instanceof WorksetIterationNode ? ((WorksetIterationNode) node).getNextWorkset() : ((WorksetIterationPlanNode) node).getNextWorkSetPlanNode(); DumpableNode<?> solutionDelta = node instanceof WorksetIterationNode ? ((WorksetIterationNode) node).getSolutionSetDelta() : ((WorksetIterationPlanNode) node).getSolutionSetDeltaPlanNode(); DumpableNode<?> workset = node instanceof WorksetIterationNode ? ((WorksetIterationNode) node).getWorksetNode() : ((WorksetIterationPlanNode) node).getWorksetPlanNode(); DumpableNode<?> solutionSet = node instanceof WorksetIterationNode ? ((WorksetIterationNode) node).getSolutionSetNode() : ((WorksetIterationPlanNode) node).getSolutionSetPlanNode(); writer.print("\t\t\"step_function\": [\n"); visit(worksetRoot, writer, true); visit(solutionDelta, writer, false); writer.print("\n\t\t],\n"); writer.print("\t\t\"workset\": " + this.nodeIds.get(workset) + ",\n"); writer.print("\t\t\"solution_set\": " + this.nodeIds.get(solutionSet) + ",\n"); writer.print("\t\t\"next_workset\": " + this.nodeIds.get(worksetRoot) + ",\n"); writer.print("\t\t\"solution_delta\": " + this.nodeIds.get(solutionDelta) + ",\n"); } // print the id writer.print("\t\t\"id\": " + this.nodeIds.get(node)); final String type; String contents; if (n instanceof DataSinkNode) { type = "sink"; contents = n.getOperator().toString(); } else if (n instanceof DataSourceNode) { type = "source"; contents = n.getOperator().toString(); } else if (n instanceof BulkIterationNode) { type = "bulk_iteration"; contents = n.getOperator().getName(); } else if (n instanceof WorksetIterationNode) { type = "workset_iteration"; contents = n.getOperator().getName(); } else if (n instanceof BinaryUnionNode) { type = "pact"; contents = ""; } else { type = "pact"; contents = n.getOperator().getName(); } contents = StringUtils.showControlCharacters(contents); if (encodeForHTML) { contents = StringEscapeUtils.escapeHtml4(contents); contents = contents.replace("\\", "\"); } String name = n.getOperatorName(); if (name.equals("Reduce") && (node instanceof SingleInputPlanNode) && ((SingleInputPlanNode) node).getDriverStrategy() == DriverStrategy.SORTED_GROUP_COMBINE) { name = "Combine"; } // output the type identifier writer.print(",\n\t\t\"type\": \"" + type + "\""); // output node name writer.print(",\n\t\t\"pact\": \"" + name + "\""); // output node contents writer.print(",\n\t\t\"contents\": \"" + contents + "\""); // parallelism writer.print( ",\n\t\t\"parallelism\": \"" + (n.getParallelism() >= 1 ? n.getParallelism() : "default") + "\""); // output node predecessors Iterator<? extends DumpableConnection<?>> inConns = node.getDumpableInputs().iterator(); String child1name = "", child2name = ""; if (inConns != null && inConns.hasNext()) { // start predecessor list writer.print(",\n\t\t\"predecessors\": ["); int inputNum = 0; while (inConns.hasNext()) { final DumpableConnection<?> inConn = inConns.next(); final DumpableNode<?> source = inConn.getSource(); writer.print(inputNum == 0 ? "\n" : ",\n"); if (inputNum == 0) { child1name += child1name.length() > 0 ? ", " : ""; child1name += source.getOptimizerNode().getOperator().getName() + " (id: " + this.nodeIds.get(source) + ")"; } else if (inputNum == 1) { child2name += child2name.length() > 0 ? ", " : ""; child2name += source.getOptimizerNode().getOperator().getName() + " (id: " + this.nodeIds.get(source) + ")"; } // output predecessor id writer.print("\t\t\t{\"id\": " + this.nodeIds.get(source)); // output connection side if (inConns.hasNext() || inputNum > 0) { writer.print(", \"side\": \"" + (inputNum == 0 ? "first" : "second") + "\""); } // output shipping strategy and channel type final Channel channel = (inConn instanceof Channel) ? (Channel) inConn : null; final ShipStrategyType shipType = channel != null ? channel.getShipStrategy() : inConn.getShipStrategy(); String shipStrategy = null; if (shipType != null) { switch (shipType) { case NONE: // nothing break; case FORWARD: shipStrategy = "Forward"; break; case BROADCAST: shipStrategy = "Broadcast"; break; case PARTITION_HASH: shipStrategy = "Hash Partition"; break; case PARTITION_RANGE: shipStrategy = "Range Partition"; break; case PARTITION_RANDOM: shipStrategy = "Redistribute"; break; case PARTITION_FORCED_REBALANCE: shipStrategy = "Rebalance"; break; case PARTITION_CUSTOM: shipStrategy = "Custom Partition"; break; default: throw new CompilerException("Unknown ship strategy '" + inConn.getShipStrategy().name() + "' in JSON generator."); } } if (channel != null && channel.getShipStrategyKeys() != null && channel.getShipStrategyKeys().size() > 0) { shipStrategy += " on " + (channel.getShipStrategySortOrder() == null ? channel.getShipStrategyKeys().toString() : Utils.createOrdering(channel.getShipStrategyKeys(), channel.getShipStrategySortOrder()).toString()); } if (shipStrategy != null) { writer.print(", \"ship_strategy\": \"" + shipStrategy + "\""); } if (channel != null) { String localStrategy = null; switch (channel.getLocalStrategy()) { case NONE: break; case SORT: localStrategy = "Sort"; break; case COMBININGSORT: localStrategy = "Sort (combining)"; break; default: throw new CompilerException("Unknown local strategy " + channel.getLocalStrategy().name()); } if (channel != null && channel.getLocalStrategyKeys() != null && channel.getLocalStrategyKeys().size() > 0) { localStrategy += " on " + (channel.getLocalStrategySortOrder() == null ? channel.getLocalStrategyKeys().toString() : Utils.createOrdering(channel.getLocalStrategyKeys(), channel.getLocalStrategySortOrder()).toString()); } if (localStrategy != null) { writer.print(", \"local_strategy\": \"" + localStrategy + "\""); } if (channel != null && channel.getTempMode() != TempMode.NONE) { String tempMode = channel.getTempMode().toString(); writer.print(", \"temp_mode\": \"" + tempMode + "\""); } if (channel != null) { String exchangeMode = channel.getDataExchangeMode().toString(); writer.print(", \"exchange_mode\": \"" + exchangeMode + "\""); } } writer.print('}'); inputNum++; } // finish predecessors writer.print("\n\t\t]"); } //--------------------------------------------------------------------------------------- // the part below here is relevant only to plan nodes with concrete strategies, etc //--------------------------------------------------------------------------------------- final PlanNode p = node.getPlanNode(); if (p == null) { // finish node writer.print("\n\t}"); return true; } // local strategy String locString = null; if (p.getDriverStrategy() != null) { switch (p.getDriverStrategy()) { case NONE: case BINARY_NO_OP: break; case UNARY_NO_OP: locString = "No-Op"; break; case MAP: locString = "Map"; break; case FLAT_MAP: locString = "FlatMap"; break; case MAP_PARTITION: locString = "Map Partition"; break; case ALL_REDUCE: locString = "Reduce All"; break; case ALL_GROUP_REDUCE: case ALL_GROUP_REDUCE_COMBINE: locString = "Group Reduce All"; break; case SORTED_REDUCE: locString = "Sorted Reduce"; break; case SORTED_PARTIAL_REDUCE: locString = "Sorted Combine/Reduce"; break; case SORTED_GROUP_REDUCE: locString = "Sorted Group Reduce"; break; case SORTED_GROUP_COMBINE: locString = "Sorted Combine"; break; case HYBRIDHASH_BUILD_FIRST: locString = "Hybrid Hash (build: " + child1name + ")"; break; case HYBRIDHASH_BUILD_SECOND: locString = "Hybrid Hash (build: " + child2name + ")"; break; case HYBRIDHASH_BUILD_FIRST_CACHED: locString = "Hybrid Hash (CACHED) (build: " + child1name + ")"; break; case HYBRIDHASH_BUILD_SECOND_CACHED: locString = "Hybrid Hash (CACHED) (build: " + child2name + ")"; break; case NESTEDLOOP_BLOCKED_OUTER_FIRST: locString = "Nested Loops (Blocked Outer: " + child1name + ")"; break; case NESTEDLOOP_BLOCKED_OUTER_SECOND: locString = "Nested Loops (Blocked Outer: " + child2name + ")"; break; case NESTEDLOOP_STREAMED_OUTER_FIRST: locString = "Nested Loops (Streamed Outer: " + child1name + ")"; break; case NESTEDLOOP_STREAMED_OUTER_SECOND: locString = "Nested Loops (Streamed Outer: " + child2name + ")"; break; case INNER_MERGE: locString = "Merge"; break; case CO_GROUP: locString = "Co-Group"; break; default: locString = p.getDriverStrategy().name(); break; } if (locString != null) { writer.print(",\n\t\t\"driver_strategy\": \""); writer.print(locString); writer.print("\""); } } { // output node global properties final GlobalProperties gp = p.getGlobalProperties(); writer.print(",\n\t\t\"global_properties\": [\n"); addProperty(writer, "Partitioning", gp.getPartitioning().name(), true); if (gp.getPartitioningFields() != null) { addProperty(writer, "Partitioned on", gp.getPartitioningFields().toString(), false); } if (gp.getPartitioningOrdering() != null) { addProperty(writer, "Partitioning Order", gp.getPartitioningOrdering().toString(), false); } else { addProperty(writer, "Partitioning Order", "(none)", false); } if (n.getUniqueFields() == null || n.getUniqueFields().size() == 0) { addProperty(writer, "Uniqueness", "not unique", false); } else { addProperty(writer, "Uniqueness", n.getUniqueFields().toString(), false); } writer.print("\n\t\t]"); } { // output node local properties LocalProperties lp = p.getLocalProperties(); writer.print(",\n\t\t\"local_properties\": [\n"); if (lp.getOrdering() != null) { addProperty(writer, "Order", lp.getOrdering().toString(), true); } else { addProperty(writer, "Order", "(none)", true); } if (lp.getGroupedFields() != null && lp.getGroupedFields().size() > 0) { addProperty(writer, "Grouped on", lp.getGroupedFields().toString(), false); } else { addProperty(writer, "Grouping", "not grouped", false); } if (n.getUniqueFields() == null || n.getUniqueFields().size() == 0) { addProperty(writer, "Uniqueness", "not unique", false); } else { addProperty(writer, "Uniqueness", n.getUniqueFields().toString(), false); } writer.print("\n\t\t]"); } // output node size estimates writer.print(",\n\t\t\"estimates\": [\n"); addProperty(writer, "Est. Output Size", n.getEstimatedOutputSize() == -1 ? "(unknown)" : formatNumber(n.getEstimatedOutputSize(), "B"), true); addProperty(writer, "Est. Cardinality", n.getEstimatedNumRecords() == -1 ? "(unknown)" : formatNumber(n.getEstimatedNumRecords()), false); writer.print("\t\t]"); // output node cost if (p.getNodeCosts() != null) { writer.print(",\n\t\t\"costs\": [\n"); addProperty(writer, "Network", p.getNodeCosts().getNetworkCost() == -1 ? "(unknown)" : formatNumber(p.getNodeCosts().getNetworkCost(), "B"), true); addProperty(writer, "Disk I/O", p.getNodeCosts().getDiskCost() == -1 ? "(unknown)" : formatNumber(p.getNodeCosts().getDiskCost(), "B"), false); addProperty(writer, "CPU", p.getNodeCosts().getCpuCost() == -1 ? "(unknown)" : formatNumber(p.getNodeCosts().getCpuCost(), ""), false); addProperty(writer, "Cumulative Network", p.getCumulativeCosts().getNetworkCost() == -1 ? "(unknown)" : formatNumber(p.getCumulativeCosts().getNetworkCost(), "B"), false); addProperty(writer, "Cumulative Disk I/O", p.getCumulativeCosts().getDiskCost() == -1 ? "(unknown)" : formatNumber(p.getCumulativeCosts().getDiskCost(), "B"), false); addProperty(writer, "Cumulative CPU", p.getCumulativeCosts().getCpuCost() == -1 ? "(unknown)" : formatNumber(p.getCumulativeCosts().getCpuCost(), ""), false); writer.print("\n\t\t]"); } // output the node compiler hints if (n.getOperator().getCompilerHints() != null) { CompilerHints hints = n.getOperator().getCompilerHints(); CompilerHints defaults = new CompilerHints(); String size = hints.getOutputSize() == defaults.getOutputSize() ? "(none)" : String.valueOf(hints.getOutputSize()); String card = hints.getOutputCardinality() == defaults.getOutputCardinality() ? "(none)" : String.valueOf(hints.getOutputCardinality()); String width = hints.getAvgOutputRecordSize() == defaults.getAvgOutputRecordSize() ? "(none)" : String.valueOf(hints.getAvgOutputRecordSize()); String filter = hints.getFilterFactor() == defaults.getFilterFactor() ? "(none)" : String.valueOf(hints.getFilterFactor()); writer.print(",\n\t\t\"compiler_hints\": [\n"); addProperty(writer, "Output Size (bytes)", size, true); addProperty(writer, "Output Cardinality", card, false); addProperty(writer, "Avg. Output Record Size (bytes)", width, false); addProperty(writer, "Filter Factor", filter, false); writer.print("\t\t]"); } // finish node writer.print("\n\t}"); return true; }
From source file:org.apache.flink.runtime.jobgraph.jsonplan.JsonPlanGenerator.java
public static String generatePlan(JobGraph jg) { try {//from w w w . j a v a 2 s. co m final StringWriter writer = new StringWriter(1024); final JsonFactory factory = new JsonFactory(); final JsonGenerator gen = factory.createGenerator(writer); // start of everything gen.writeStartObject(); gen.writeStringField("jid", jg.getJobID().toString()); gen.writeStringField("name", jg.getName()); gen.writeArrayFieldStart("nodes"); // info per vertex for (JobVertex vertex : jg.getVertices()) { String operator = vertex.getOperatorName() != null ? vertex.getOperatorName() : NOT_SET; String operatorDescr = vertex.getOperatorDescription() != null ? vertex.getOperatorDescription() : NOT_SET; String optimizerProps = vertex.getResultOptimizerProperties() != null ? vertex.getResultOptimizerProperties() : EMPTY; String description = vertex.getOperatorPrettyName() != null ? vertex.getOperatorPrettyName() : vertex.getName(); // make sure the encoding is HTML pretty description = StringEscapeUtils.escapeHtml4(description); description = description.replace("\n", "<br/>"); description = description.replace("\\", "\"); operatorDescr = StringEscapeUtils.escapeHtml4(operatorDescr); operatorDescr = operatorDescr.replace("\n", "<br/>"); gen.writeStartObject(); // write the core properties gen.writeStringField("id", vertex.getID().toString()); gen.writeNumberField("parallelism", vertex.getParallelism()); gen.writeStringField("operator", operator); gen.writeStringField("operator_strategy", operatorDescr); gen.writeStringField("description", description); if (!vertex.isInputVertex()) { // write the input edge properties gen.writeArrayFieldStart("inputs"); List<JobEdge> inputs = vertex.getInputs(); for (int inputNum = 0; inputNum < inputs.size(); inputNum++) { JobEdge edge = inputs.get(inputNum); if (edge.getSource() == null) { continue; } JobVertex predecessor = edge.getSource().getProducer(); String shipStrategy = edge.getShipStrategyName(); String preProcessingOperation = edge.getPreProcessingOperationName(); String operatorLevelCaching = edge.getOperatorLevelCachingDescription(); gen.writeStartObject(); gen.writeNumberField("num", inputNum); gen.writeStringField("id", predecessor.getID().toString()); if (shipStrategy != null) { gen.writeStringField("ship_strategy", shipStrategy); } if (preProcessingOperation != null) { gen.writeStringField("local_strategy", preProcessingOperation); } if (operatorLevelCaching != null) { gen.writeStringField("caching", operatorLevelCaching); } gen.writeStringField("exchange", edge.getSource().getResultType().name().toLowerCase()); gen.writeEndObject(); } gen.writeEndArray(); } // write the optimizer properties gen.writeFieldName("optimizer_properties"); gen.writeRawValue(optimizerProps); gen.writeEndObject(); } // end of everything gen.writeEndArray(); gen.writeEndObject(); gen.close(); return writer.toString(); } catch (Exception e) { throw new RuntimeException("Failed to generate plan", e); } }
From source file:org.apache.jmeter.functions.EscapeHtml.java
/** {@inheritDoc} */ @Override/*from w w w. jav a 2s.c om*/ public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException { String rawString = ((CompoundVariable) values[0]).execute(); return StringEscapeUtils.escapeHtml4(rawString); }
From source file:org.apache.jmeter.report.dashboard.HtmlTemplateExporter.java
@Override public void export(SampleContext context, File file, ReportGeneratorConfiguration configuration) throws ExportException { Validate.notNull(context, MUST_NOT_BE_NULL, "context"); Validate.notNull(file, MUST_NOT_BE_NULL, "file"); Validate.notNull(configuration, MUST_NOT_BE_NULL, "configuration"); LOG.debug("Start template processing"); // Create data context and populate it DataContext dataContext = new DataContext(); // Get the configuration of the current exporter final ExporterConfiguration exportCfg = configuration.getExportConfigurations().get(getName()); // Get template directory property value File templateDirectory = getPropertyFromConfig(exportCfg, TEMPLATE_DIR, new File(JMeterUtils.getJMeterBinDir(), TEMPLATE_DIR_NAME_DEFAULT), File.class); if (!templateDirectory.isDirectory()) { String message = String.format(INVALID_TEMPLATE_DIRECTORY_FMT, templateDirectory.getAbsolutePath()); LOG.error(message);/*from w w w . ja va 2 s . c o m*/ throw new ExportException(message); } // Get output directory property value File outputDir = getPropertyFromConfig(exportCfg, OUTPUT_DIR, new File(JMeterUtils.getJMeterBinDir(), OUTPUT_DIR_NAME_DEFAULT), File.class); String globallyDefinedOutputDir = JMeterUtils.getProperty(JMeter.JMETER_REPORT_OUTPUT_DIR_PROPERTY); if (!StringUtils.isEmpty(globallyDefinedOutputDir)) { outputDir = new File(globallyDefinedOutputDir); } JOrphanUtils.canSafelyWriteToFolder(outputDir); LOG.info("Will generate dashboard in folder:" + outputDir.getAbsolutePath()); // Add the flag defining whether only sample series are filtered to the // context final boolean filtersOnlySampleSeries = exportCfg.filtersOnlySampleSeries(); addToContext(DATA_CTX_FILTERS_ONLY_SAMPLE_SERIES, Boolean.valueOf(filtersOnlySampleSeries), dataContext); // Add the series filter to the context final String seriesFilter = exportCfg.getSeriesFilter(); Pattern filterPattern = null; if (StringUtils.isNotBlank(seriesFilter)) { try { filterPattern = Pattern.compile(seriesFilter); } catch (PatternSyntaxException ex) { LOG.error(String.format("Invalid series filter: \"%s\", %s", seriesFilter, ex.getDescription())); } } addToContext(DATA_CTX_SERIES_FILTER, seriesFilter, dataContext); // Add the flag defining whether only controller series are displayed final boolean showControllerSeriesOnly = exportCfg.showControllerSeriesOnly(); addToContext(DATA_CTX_SHOW_CONTROLLERS_ONLY, Boolean.valueOf(showControllerSeriesOnly), dataContext); JsonizerVisitor jsonizer = new JsonizerVisitor(); Map<String, Object> storedData = context.getData(); // Add begin date consumer result to the data context addResultToContext(ReportGenerator.BEGIN_DATE_CONSUMER_NAME, storedData, dataContext, jsonizer); // Add end date summary consumer result to the data context addResultToContext(ReportGenerator.END_DATE_CONSUMER_NAME, storedData, dataContext, jsonizer); // Add Apdex summary consumer result to the data context addResultToContext(ReportGenerator.APDEX_SUMMARY_CONSUMER_NAME, storedData, dataContext, jsonizer); // Add errors summary consumer result to the data context addResultToContext(ReportGenerator.ERRORS_SUMMARY_CONSUMER_NAME, storedData, dataContext, jsonizer); // Add requests summary consumer result to the data context addResultToContext(ReportGenerator.REQUESTS_SUMMARY_CONSUMER_NAME, storedData, dataContext, jsonizer); // Add statistics summary consumer result to the data context addResultToContext(ReportGenerator.STATISTICS_SUMMARY_CONSUMER_NAME, storedData, dataContext, jsonizer); // Collect graph results from sample context and transform them into // Json strings to inject in the data context ExtraOptionsResultCustomizer customizer = new ExtraOptionsResultCustomizer(); EmptyGraphChecker checker = new EmptyGraphChecker(filtersOnlySampleSeries, showControllerSeriesOnly, filterPattern); for (Map.Entry<String, GraphConfiguration> graphEntry : configuration.getGraphConfigurations().entrySet()) { final String graphId = graphEntry.getKey(); final GraphConfiguration graphConfiguration = graphEntry.getValue(); final SubConfiguration extraOptions = exportCfg.getGraphExtraConfigurations().get(graphId); // Initialize customizer and checker customizer.setExtraOptions(extraOptions); checker.setExcludesControllers(graphConfiguration.excludesControllers()); checker.setGraphId(graphId); // Export graph data addResultToContext(graphId, storedData, dataContext, jsonizer, customizer, checker); } // Replace the begin date with its formatted string and store the old // timestamp long oldTimestamp = formatTimestamp(ReportGenerator.BEGIN_DATE_CONSUMER_NAME, dataContext); // Replace the end date with its formatted string formatTimestamp(ReportGenerator.END_DATE_CONSUMER_NAME, dataContext); // Add time zone offset (that matches the begin date) to the context TimeZone timezone = TimeZone.getDefault(); addToContext(DATA_CTX_TIMEZONE_OFFSET, Integer.valueOf(timezone.getOffset(oldTimestamp)), dataContext); // Add report title to the context if (!StringUtils.isEmpty(configuration.getReportTitle())) { dataContext.put(DATA_CTX_REPORT_TITLE, StringEscapeUtils.escapeHtml4(configuration.getReportTitle())); } // Add the test file name to the context addToContext(DATA_CTX_TESTFILE, file.getName(), dataContext); // Add the overall filter property to the context addToContext(DATA_CTX_OVERALL_FILTER, configuration.getSampleFilter(), dataContext); // Walk template directory to copy files and process templated ones Configuration templateCfg = new Configuration(Configuration.getVersion()); try { templateCfg.setDirectoryForTemplateLoading(templateDirectory); templateCfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); LOG.info("Report will be generated in:" + outputDir.getAbsolutePath() + ", creating folder structure"); FileUtils.forceMkdir(outputDir); TemplateVisitor visitor = new TemplateVisitor(templateDirectory.toPath(), outputDir.toPath(), templateCfg, dataContext); Files.walkFileTree(templateDirectory.toPath(), visitor); } catch (IOException ex) { throw new ExportException("Unable to process template files.", ex); } LOG.debug("End of template processing"); }
From source file:org.apache.nifi.web.server.HostHeaderHandler.java
/** * Returns an error message to the response and marks the request as handled if the host header is not valid. * Otherwise passes the request on to the next scoped handler. * * @param target the target (not relevant here) * @param baseRequest the original request object * @param request the request as an HttpServletRequest * @param response the current response/*w ww . ja va 2 s. co m*/ */ @Override public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { final String hostHeader = request.getHeader("Host"); logger.debug("Received request [" + request.getRequestURI() + "] with host header: " + hostHeader); if (!hostHeaderIsValid(hostHeader)) { logger.warn("Request host header [" + hostHeader + "] different from web hostname [" + serverName + "(:" + serverPort + ")]. Overriding to [" + serverName + ":" + serverPort + request.getRequestURI() + "]"); response.setContentType("text/html; charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); PrintWriter out = response.getWriter(); out.println("<h1>System Error</h1>"); out.println( "<h2>The request contained an invalid host header [" + StringEscapeUtils.escapeHtml4(hostHeader) + "] in the request [" + StringEscapeUtils.escapeHtml4(request.getRequestURI()) + "]. Check for request manipulation or third-party intercept. </h2>"); baseRequest.setHandled(true); } }
From source file:org.apache.pluto.container.bean.mvc.EncodersImpl.java
@Override public String html(String markup) { return StringEscapeUtils.escapeHtml4(markup); }
From source file:org.apache.portals.pluto.demo.chat.ChatHistory.java
/** * returns the markup for the stored messages *//*from ww w . j ava2 s .c o m*/ public String getMarkup() { StringBuilder txt = new StringBuilder(128); synchronized (messages) { for (String msg : messages) { txt.append("<p>").append(StringEscapeUtils.escapeHtml4(msg)).append("</p>\n"); } } return txt.toString(); }
From source file:org.apache.portals.pluto.demo.chat.HelloWorldRender.java
/** * Bean portlet render method for "BeanHelloWorld" portlet. The portletNames * attribute specifies the portlet name or list of portlet names using the method. * This annotation implicitly defines a portlet or list of portlets. Further * configuration can be provided, but is not required. *///www. j a v a 2 s .com @RenderMethod(portletNames = { "BeanPortletDemo" }) public String methodName() { // In it's simplest form, the render method just returns text. // The content type is set through the annotation. StringBuilder txt = new StringBuilder(128); txt.append("<h3>Hello \n"); // Get the name from the bean. If it hasn't been set, just greet the world. if (nameBean.getName() != null) { txt.append(StringEscapeUtils.escapeHtml4(nameBean.getName())); } else { txt.append("World\n"); } txt.append("!!</h3>"); return txt.toString(); }
From source file:org.apache.sling.commons.fsclassloader.impl.FSClassLoaderWebConsole.java
@Override protected void renderContent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Map<String, ScriptFiles> scripts = new LinkedHashMap<String, ScriptFiles>(); readFiles(root, scripts);//from www . ja v a 2s . c o m Writer w = response.getWriter(); w.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + RES_LOC + "/prettify.css\"></link>"); w.write("<script type=\"text/javascript\" src=\"" + RES_LOC + "/prettify.js\"></script>"); w.write("<script type=\"text/javascript\" src=\"" + RES_LOC + "/fsclassloader.js\"></script>"); w.write("<script>$(document).ready(prettyPrint);</script>"); w.write("<style>.prettyprint ol.linenums > li { list-style-type: decimal; } pre.prettyprint { white-space: pre-wrap; }</style>"); String file = request.getParameter("view"); File toView = new File(root + file); w.write("<div id=\"classes\">"); if (!StringUtils.isEmpty(file)) { if (isValid(toView)) { w.write("<p class=\"statline ui-state-highlight\">Viewing Script: " + root + file + "</p><br/><br/>"); ScriptFiles scriptFiles = new ScriptFiles(toView); w.write("<table class=\"nicetable ui-widget\">"); w.write("<tr class=\"header ui-widget-header\">"); w.write("<th>Script</th>"); w.write("<th>Class</th>"); w.write("<th>Deps</th>"); w.write("<th>Java</th>"); w.write("</tr>"); w.write("<tr class=\"ui-state-default\">"); w.write("<td>" + scriptFiles.getScript() + "</td>"); w.write("<td>[<a href=\"?download=" + scriptFiles.getClassFile() + "\" target=\"_blank\">download</a>]</td>"); w.write("<td>[<a href=\"?download=" + scriptFiles.getDepsFile() + "\" target=\"_blank\">download</a>]</td>"); w.write("<td>[<a href=\"?download=" + scriptFiles.getJavaFile() + "\" target=\"_blank\">download</a>]</td>"); w.write("</tr>"); w.write("</table><br/><br/>"); InputStream is = null; try { is = new FileInputStream(toView); String contents = IOUtils.toString(is, "UTF-8"); w.write("<pre class=\"prettyprint linenums\">"); w.write(StringEscapeUtils.escapeHtml4(contents)); w.write("</pre>"); } finally { IOUtils.closeQuietly(is); } } else { response.sendError(404, "File " + file + " not found"); } } else { w.write("<p class=\"statline ui-state-highlight\">File System ClassLoader Root: " + root + " <span style=\"float: right\"><button type='button' id='clear'>Clear Class Loader</button></span></p>"); if (scripts.values().size() > 0) { w.write("<table class=\"nicetable ui-widget fsclassloader-has-classes\">"); } else { w.write("<table class=\"nicetable ui-widget\">"); } w.write("<tr class=\"header ui-widget-header\">"); w.write("<th>View</th>"); w.write("<th>Script</th>"); w.write("</tr>"); int i = 0; for (ScriptFiles scriptFiles : scripts.values()) { w.write("<tr class=\"" + (i % 2 == 0 ? "even" : "odd") + " ui-state-default\">"); w.write("<td>[<a href=\"?view=" + scriptFiles.getJavaFile() + "\">view</a>]</td>"); w.write("<td>" + scriptFiles.getScript() + "</td>"); w.write("</tr>"); i++; } w.write("</table>"); } w.write("</div>"); }