Search in sources :

Example 1 with BOperator

use of com.ibm.streamsx.topology.builder.BOperator in project streamsx.topology by IBMStreams.

the class DependencyResolver method resolveDependencies.

/**
     * Resolve the dependencies.
     * Creates entries in the graph config that will
     * result in files being copied into the toolkit.
     */
public void resolveDependencies() throws IOException, URISyntaxException {
    JSONObject graphConfig = topology.builder().getConfig();
    JSONArray includes = (JSONArray) graphConfig.get("includes");
    if (includes == null)
        graphConfig.put("includes", includes = new JSONArray());
    for (BOperatorInvocation op : operatorToJarDependencies.keySet()) {
        ArrayList<String> jars = new ArrayList<String>();
        for (Path source : operatorToJarDependencies.get(op)) {
            String jarName = resolveDependency(source, includes);
            jars.add("impl/lib/" + jarName);
        }
        String[] jarPaths = jars.toArray(new String[jars.size()]);
        op.setParameter("jar", jarPaths);
    }
    ArrayList<String> jars = new ArrayList<String>();
    for (Path source : globalDependencies) {
        String jarName = resolveDependency(source, includes);
        jars.add("impl/lib/" + jarName);
    }
    List<BOperator> ops = topology.builder().getOps();
    if (jars.size() != 0) {
        for (BOperator op : ops) {
            if (op instanceof BOperatorInvocation) {
                BOperatorInvocation bop = (BOperatorInvocation) op;
                if (Functional.class.isAssignableFrom(bop.op().getOperatorClass())) {
                    JSONObject params = (JSONObject) bop.json().get("parameters");
                    JSONObject op_jars = (JSONObject) params.get("jar");
                    if (null == op_jars) {
                        JSONObject val = new JSONObject();
                        val.put("value", new JSONArray());
                        params.put("jar", val);
                        op_jars = val;
                    }
                    JSONArray value = (JSONArray) op_jars.get("value");
                    for (String jar : jars) {
                        value.add(jar);
                    }
                }
            }
        }
    }
    for (Artifact dep : globalFileDependencies) resolveFileDependency(dep, includes);
}
Also used : Path(java.nio.file.Path) JSONObject(com.ibm.json.java.JSONObject) JSONArray(com.ibm.json.java.JSONArray) ArrayList(java.util.ArrayList) BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) BOperator(com.ibm.streamsx.topology.builder.BOperator)

Aggregations

JSONArray (com.ibm.json.java.JSONArray)1 JSONObject (com.ibm.json.java.JSONObject)1 BOperator (com.ibm.streamsx.topology.builder.BOperator)1 BOperatorInvocation (com.ibm.streamsx.topology.builder.BOperatorInvocation)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1