Search in sources :

Example 1 with ToolkitInfoModelType

use of com.ibm.streamsx.topology.internal.toolkit.info.ToolkitInfoModelType in project streamsx.topology by IBMStreams.

the class ToolkitRemoteContext method addToolkitInfo.

/**
     * Create an info.xml file for the toolkit.
     * @throws URISyntaxException 
     */
private void addToolkitInfo(File toolkitRoot, JsonObject jsonGraph) throws JAXBException, FileNotFoundException, IOException, URISyntaxException {
    File infoFile = new File(toolkitRoot, "info.xml");
    ToolkitInfoModelType info = new ToolkitInfoModelType();
    info.setIdentity(new IdentityType());
    info.getIdentity().setName(toolkitRoot.getName());
    info.getIdentity().setDescription(new DescriptionType());
    info.getIdentity().setVersion("1.0.0." + System.currentTimeMillis());
    info.getIdentity().setRequiredProductVersion("4.0.1.0");
    DependenciesType dependencies = new DependenciesType();
    List<ToolkitDependencyType> toolkits = dependencies.getToolkit();
    GsonUtilities.objectArray(object(jsonGraph, "spl"), TOOLKITS_JSON, tk -> {
        ToolkitDependencyType depTkInfo;
        String root = jstring(tk, "root");
        if (root != null) {
            try {
                depTkInfo = TkInfo.getTookitDependency(root);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        } else {
            depTkInfo = new ToolkitDependencyType();
            depTkInfo.setName(jstring(tk, "name"));
            depTkInfo.setVersion(jstring(tk, "version"));
        }
        toolkits.add(depTkInfo);
    });
    File topologyToolkitRoot = TkInfo.getTopologyToolkitRoot();
    toolkits.add(TkInfo.getTookitDependency(topologyToolkitRoot.getAbsolutePath()));
    info.setDependencies(dependencies);
    JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    try (FileOutputStream out = new FileOutputStream(infoFile)) {
        m.marshal(info, out);
    }
}
Also used : IdentityType(com.ibm.streamsx.topology.internal.toolkit.info.IdentityType) Marshaller(javax.xml.bind.Marshaller) DescriptionType(com.ibm.streamsx.topology.internal.toolkit.info.DescriptionType) ToolkitDependencyType(com.ibm.streamsx.topology.internal.toolkit.info.ToolkitDependencyType) ToolkitInfoModelType(com.ibm.streamsx.topology.internal.toolkit.info.ToolkitInfoModelType) JAXBContext(javax.xml.bind.JAXBContext) DependenciesType(com.ibm.streamsx.topology.internal.toolkit.info.DependenciesType) URISyntaxException(java.net.URISyntaxException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 2 with ToolkitInfoModelType

use of com.ibm.streamsx.topology.internal.toolkit.info.ToolkitInfoModelType in project streamsx.topology by IBMStreams.

the class TkInfo method getToolkitInfo.

/**
     * Get the full toolkit information.
     * Returns null if there is no info.xml
     */
public static ToolkitInfoModelType getToolkitInfo(File toolkitRoot) throws JAXBException {
    File infoFile = new File(toolkitRoot, "info.xml");
    if (!infoFile.exists())
        return null;
    StreamSource infoSource = new StreamSource(infoFile);
    JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    ToolkitInfoModelType tkinfo = jaxbUnmarshaller.unmarshal(infoSource, ToolkitInfoModelType.class).getValue();
    return tkinfo;
}
Also used : StreamSource(javax.xml.transform.stream.StreamSource) ToolkitInfoModelType(com.ibm.streamsx.topology.internal.toolkit.info.ToolkitInfoModelType) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Example 3 with ToolkitInfoModelType

use of com.ibm.streamsx.topology.internal.toolkit.info.ToolkitInfoModelType in project streamsx.topology by IBMStreams.

the class TkInfo method getTookitDependency.

public static ToolkitDependencyType getTookitDependency(String toolkitRoot) throws JAXBException {
    ToolkitInfoModelType depTkInfo = getToolkitInfo(new File(toolkitRoot));
    String depTkVersion = depTkInfo.getIdentity().getVersion();
    String[] elements = depTkVersion.split("\\.");
    int next = Integer.valueOf(elements[0]) + 1;
    String versionRange = "[" + elements[0] + "." + elements[1] + "," + next + ".0)";
    ToolkitDependencyType depTk = new ToolkitDependencyType();
    depTk.setName(depTkInfo.getIdentity().getName());
    depTk.setVersion(versionRange);
    return depTk;
}
Also used : ToolkitDependencyType(com.ibm.streamsx.topology.internal.toolkit.info.ToolkitDependencyType) ToolkitInfoModelType(com.ibm.streamsx.topology.internal.toolkit.info.ToolkitInfoModelType) File(java.io.File)

Example 4 with ToolkitInfoModelType

use of com.ibm.streamsx.topology.internal.toolkit.info.ToolkitInfoModelType in project streamsx.topology by IBMStreams.

the class SPL method addToolkit.

/**
     * Add a dependency on an SPL toolkit.
     * @param te Element within the topology.
     * @param toolkitRoot Root directory of the toolkit.
     * @throws IOException {@code toolkitRoot} is not a valid path.
     */
public static void addToolkit(TopologyElement te, File toolkitRoot) throws IOException {
    JSONObject tkinfo = newToolkitDepInfo(te);
    tkinfo.put("root", toolkitRoot.getCanonicalPath());
    ToolkitInfoModelType infoModel;
    try {
        infoModel = TkInfo.getToolkitInfo(toolkitRoot);
    } catch (JAXBException e) {
        throw new IOException(e);
    }
    if (infoModel != null) {
        IdentityType tkIdentity = infoModel.getIdentity();
        tkinfo.put("name", tkIdentity.getName());
        tkinfo.put("version", tkIdentity.getVersion());
    }
}
Also used : IdentityType(com.ibm.streamsx.topology.internal.toolkit.info.IdentityType) JSONObject(com.ibm.json.java.JSONObject) JAXBException(javax.xml.bind.JAXBException) ToolkitInfoModelType(com.ibm.streamsx.topology.internal.toolkit.info.ToolkitInfoModelType) IOException(java.io.IOException)

Aggregations

ToolkitInfoModelType (com.ibm.streamsx.topology.internal.toolkit.info.ToolkitInfoModelType)4 File (java.io.File)3 IdentityType (com.ibm.streamsx.topology.internal.toolkit.info.IdentityType)2 ToolkitDependencyType (com.ibm.streamsx.topology.internal.toolkit.info.ToolkitDependencyType)2 IOException (java.io.IOException)2 JAXBContext (javax.xml.bind.JAXBContext)2 JAXBException (javax.xml.bind.JAXBException)2 JSONObject (com.ibm.json.java.JSONObject)1 DependenciesType (com.ibm.streamsx.topology.internal.toolkit.info.DependenciesType)1 DescriptionType (com.ibm.streamsx.topology.internal.toolkit.info.DescriptionType)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 URISyntaxException (java.net.URISyntaxException)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 StreamSource (javax.xml.transform.stream.StreamSource)1