Search in sources :

Example 51 with JSONObject

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);
}
Also used : JSONObject(com.ibm.json.java.JSONObject) JSONArray(com.ibm.json.java.JSONArray)

Example 52 with JSONObject

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);
}
Also used : JSONObject(com.ibm.json.java.JSONObject)

Example 53 with JSONObject

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);
}
Also used : JSONObject(com.ibm.json.java.JSONObject) HashMap(java.util.HashMap) JSONObject(com.ibm.json.java.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 54 with JSONObject

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.");
        }
    });
}
Also used : JSONObject(com.ibm.json.java.JSONObject) JsonObject(com.google.gson.JsonObject) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) SPLGenerator(com.ibm.streamsx.topology.generator.spl.SPLGenerator) Test(org.junit.Test)

Example 55 with JSONObject

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();
}
Also used : JSONObject(com.ibm.json.java.JSONObject)

Aggregations

JSONObject (com.ibm.json.java.JSONObject)56 JSONArray (com.ibm.json.java.JSONArray)19 Topology (com.ibm.streamsx.topology.Topology)18 Test (org.junit.Test)18 TestTopology (com.ibm.streamsx.topology.test.TestTopology)14 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)6 Tester (com.ibm.streamsx.topology.tester.Tester)5 JsonObject (com.google.gson.JsonObject)4 HashMap (java.util.HashMap)4 Random (java.util.Random)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 OrderedJSONObject (com.ibm.json.java.OrderedJSONObject)2 StreamConnection (com.ibm.streams.flow.declare.StreamConnection)2 StreamSchema (com.ibm.streams.operator.StreamSchema)2 BOperatorInvocation (com.ibm.streamsx.topology.builder.BOperatorInvocation)2 File (java.io.File)2 IOException (java.io.IOException)2 Map (java.util.Map)2 Attribute (com.ibm.streams.operator.Attribute)1