use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class SourceInfo method setSourceInfo.
public static void setSourceInfo(BOperatorInvocation bop, Class<?> calledClass) {
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
StackTraceElement calledMethod = null;
StackTraceElement caller = null;
boolean foundCalled = false;
for (int i = 0; i < stack.length; i++) {
StackTraceElement ste = stack[i];
if (calledClass.getName().equals(ste.getClassName())) {
foundCalled = true;
calledMethod = ste;
continue;
}
if (foundCalled) {
caller = ste;
break;
}
}
JSONArray ja = (JSONArray) bop.json().get("sourcelocation");
if (ja == null)
bop.json().put("sourcelocation", ja = new JSONArray());
JSONObject sourceInfo = new JSONObject();
if (caller != null) {
if (caller.getFileName() != null)
sourceInfo.put("file", caller.getFileName());
if (caller.getClassName() != null)
sourceInfo.put("class", caller.getClassName());
if (caller.getMethodName() != null)
sourceInfo.put("method", caller.getMethodName());
if (caller.getLineNumber() > 0)
sourceInfo.put("line", caller.getLineNumber());
}
if (calledMethod != null)
sourceInfo.put("topology.method", calledMethod.getMethodName());
ja.add(sourceInfo);
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class DependencyResolver method resolveFileDependency.
/**
* Copy the Artifact to the toolkit
*/
private void resolveFileDependency(Artifact a, JSONArray includes) {
JSONObject include = new JSONObject();
include.put("source", a.absPath.toString());
include.put("target", a.dstDirName);
includes.add(include);
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class SubmissionParameterManager method initializeEmbedded.
/**
* Initialize EMBEDDED submission parameter value information
* from topology's graph and StreamsContext.submit() config.
* @param builder the topology's builder
* @param config StreamsContext.submit() configuration
*/
public static synchronized void initializeEmbedded(GraphBuilder builder, Map<String, Object> config) {
// N.B. in an embedded context, within a single JVM/classloader,
// multiple topologies can be executed serially as well as concurrently.
// TODO handle the concurrent case - e.g., with per-topology-submit
// managers.
// create map of all submission params used by the topology
// and the parameter's string value (initially null for no default)
// spName, spStrVal
Map<String, String> allsp = new HashMap<>();
JSONObject graph = builder.json();
JSONObject gparams = (JSONObject) graph.get("parameters");
if (gparams != null) {
for (Object o : gparams.keySet()) {
JSONObject param = (JSONObject) gparams.get((String) o);
if (TYPE_SUBMISSION_PARAMETER.equals(param.get("type"))) {
JSONObject spval = (JSONObject) param.get("value");
Object val = spval.get("defaultValue");
if (val != null)
val = val.toString();
allsp.put((String) spval.get("name"), (String) val);
}
}
}
if (allsp.isEmpty())
return;
// update values from config
@SuppressWarnings("unchecked") Map<String, Object> spValues = (Map<String, Object>) config.get(ContextProperties.SUBMISSION_PARAMS);
for (String spName : spValues.keySet()) {
if (allsp.containsKey(spName)) {
Object val = spValues.get(spName);
if (val != null)
val = val.toString();
allsp.put(spName, (String) val);
}
}
// failure if any are still undefined
for (String spName : allsp.keySet()) {
if (allsp.get(spName) == null)
throw new IllegalStateException("Submission parameter \"" + spName + "\" requires a value but none has been supplied");
}
// good to go. initialize params
params = new HashMap<>();
for (Map.Entry<String, String> e : allsp.entrySet()) {
params.put(e.getKey(), e.getValue());
}
// System.out.println("SPM.initializeEmbedded() " + params);
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class LowLatencyTest method threadedPortTest.
@Test
public void threadedPortTest() throws Exception {
assumeTrue(isMainRun());
Topology topology = newTopology("lowLatencyTest");
// Construct topology
TStream<String> ss = topology.strings("hello").lowLatency();
TStream<String> ss1 = ss.transform(getContainerId());
TStream<String> ss2 = ss1.transform(getContainerId()).endLowLatency();
SPLGenerator generator = new SPLGenerator();
JSONObject graph = topology.builder().complete();
JsonObject ggraph = JSON4JUtilities.gson(graph);
generator.generateSPL(ggraph);
GsonUtilities.objectArray(ggraph, "operators", op -> {
String lowLatencyTag = null;
JsonObject placement = object(op, CONFIG, PLACEMENT);
if (placement != null)
lowLatencyTag = jstring(placement, PLACEMENT_LOW_LATENCY_REGION_ID);
String kind = jstring(op, "kind");
JsonObject queue = object(op, "queue");
if (queue != null && (lowLatencyTag == null || lowLatencyTag.equals(""))) {
throw new IllegalStateException("Operator has threaded port when it shouldn't.");
}
if (queue != null && kind.equals("com.ibm.streamsx.topology.functional.java::FunctionTransform")) {
throw new IllegalStateException("Transform operator expecting threaded port; none found.");
}
});
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class MqttStreamsTest method toJson.
private static String toJson(Message m) {
JSONObject jo = new JSONObject();
jo.put("key", m.getKey());
jo.put("message", m.getMessage());
jo.put("topic", m.getTopic());
return jo.toString();
}
Aggregations