Search in sources :

Example 1 with NodeExecutionJobManagerFactory

use of org.knime.core.node.workflow.NodeExecutionJobManagerFactory in project knime-core by knime.

the class NodeExecutionJobManagerPool method collectJobManagerFactories.

private static void collectJobManagerFactories() {
    managerFactories = new LinkedHashMap<String, NodeExecutionJobManagerFactory>();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    if (point == null) {
        // let's throw in the default manager - otherwise things fail badly
        managerFactories.put(getDefaultJobManagerFactory().getID(), getDefaultJobManagerFactory());
        LOGGER.error("Invalid extension point: " + EXT_POINT_ID);
        throw new IllegalStateException("ACTIVATION ERROR: " + " --> Invalid extension point: " + EXT_POINT_ID);
    }
    for (IConfigurationElement elem : point.getConfigurationElements()) {
        String jobMgr = elem.getAttribute(EXT_POINT_ATTR_JOBMGR);
        String decl = elem.getDeclaringExtension().getUniqueIdentifier();
        if (jobMgr == null || jobMgr.isEmpty()) {
            LOGGER.error("The extension '" + decl + "' doesn't provide the required attribute '" + EXT_POINT_ATTR_JOBMGR + "'");
            LOGGER.error("Extension " + decl + " ignored.");
            continue;
        }
        // try instantiating the job manager.
        NodeExecutionJobManagerFactory instance = null;
        try {
            // TODO: THE THREADED MANAGER NEEDS TO BE RE-WRITTEN!
            if (jobMgr.equals(getDefaultJobManagerFactory().getID())) {
                instance = getDefaultJobManagerFactory();
            } else {
                instance = (NodeExecutionJobManagerFactory) elem.createExecutableExtension(EXT_POINT_ATTR_JOBMGR);
            }
        } catch (UnsatisfiedLinkError ule) {
            // in case an implementation tries to load an external lib
            // when the factory class gets loaded
            LOGGER.error("Unable to load a library required for '" + jobMgr + "'");
            LOGGER.error("Either specify it in the -Djava.library.path " + "option at the program's command line, or");
            LOGGER.error("include it in the LD_LIBRARY_PATH variable.");
            LOGGER.error("Extension " + jobMgr + " ('" + decl + "') ignored.", ule);
        } catch (CoreException ex) {
            Throwable cause = ex.getStatus().getException();
            if (cause != null) {
                LOGGER.error("Problems during initialization of job manager (with id '" + jobMgr + "'): " + cause.getMessage(), ex);
                if (decl != null) {
                    LOGGER.error("Extension " + decl + " ignored.");
                }
            } else {
                LOGGER.error("Problems during initialization of job manager (with id '" + jobMgr + "')", ex);
                if (decl != null) {
                    LOGGER.error("Extension " + decl + " ignored.");
                }
            }
        } catch (Throwable t) {
            LOGGER.error("Problems during initialization of job manager (with id '" + jobMgr + "')", t);
            if (decl != null) {
                LOGGER.error("Extension " + decl + " ignored.");
            }
        }
        if (instance != null) {
            /*
                 * make sure the ThreadedJobManagerFactory is always the first
                 * in the list
                 */
            if ((instance instanceof ThreadPool) && managerFactories.size() > 0) {
                Map<String, NodeExecutionJobManagerFactory> old = managerFactories;
                managerFactories = new LinkedHashMap<String, NodeExecutionJobManagerFactory>();
                managerFactories.put(instance.getID(), instance);
                for (Map.Entry<String, NodeExecutionJobManagerFactory> e : old.entrySet()) {
                    managerFactories.put(e.getKey(), e.getValue());
                }
            } else {
                managerFactories.put(instance.getID(), instance);
            }
        }
    }
}
Also used : ThreadPool(org.knime.core.util.ThreadPool) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) NodeExecutionJobManagerFactory(org.knime.core.node.workflow.NodeExecutionJobManagerFactory) ThreadNodeExecutionJobManagerFactory(org.knime.core.node.exec.ThreadNodeExecutionJobManagerFactory) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 2 with NodeExecutionJobManagerFactory

use of org.knime.core.node.workflow.NodeExecutionJobManagerFactory in project knime-core by knime.

the class NodeExecutionJobManagerPool method merge.

/**
 * Get the common settings for a set of job managers.
 * Used from {@link WorkflowManager#getCommonSettings(org.knime.core.node.workflow.NodeID...)}.
 * @param jobManagers ...
 * @return ...
 * @since 2.7
 */
public static NodeContainerSettings merge(final NodeExecutionJobManager[] jobManagers) {
    String factoryID = null;
    NodeSettings mgrSettings = null;
    boolean isFirst = true;
    for (NodeExecutionJobManager jobManager : jobManagers) {
        String curFactoryID;
        NodeSettings curMgrSettings;
        if (jobManager == null) {
            curFactoryID = null;
            curMgrSettings = null;
        } else {
            curFactoryID = jobManager.getID();
            NodeSettings temp = new NodeSettings(CFG_JOB_MANAGER_SETTINGS);
            jobManager.save(temp);
            curMgrSettings = temp;
        }
        if (isFirst) {
            isFirst = false;
            factoryID = curFactoryID;
            mgrSettings = curMgrSettings;
        } else if (ConvenienceMethods.areEqual(factoryID, curFactoryID)) {
            if (!ConvenienceMethods.areEqual(mgrSettings, curMgrSettings)) {
                mgrSettings = null;
            }
        } else {
            // different job managers
            // unassigned
            curFactoryID = null;
        }
    }
    if (factoryID == null) {
        return null;
    }
    NodeExecutionJobManagerFactory jobManagerFactory = getJobManagerFactory(factoryID);
    assert jobManagerFactory != null : "Factory ID " + factoryID + " unknown although job manager present";
    NodeExecutionJobManager instance = jobManagerFactory.getInstance();
    if (mgrSettings != null) {
        try {
            instance.load(mgrSettings);
        } catch (InvalidSettingsException e) {
            LOGGER.error("Settings could not be applied to job manager although " + "they retrieved from another identical instance.", e);
        }
    }
    NodeContainerSettings result = new NodeContainerSettings();
    result.setJobManager(instance);
    return result;
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeContainerSettings(org.knime.core.node.workflow.NodeContainer.NodeContainerSettings) NodeExecutionJobManagerFactory(org.knime.core.node.workflow.NodeExecutionJobManagerFactory) ThreadNodeExecutionJobManagerFactory(org.knime.core.node.exec.ThreadNodeExecutionJobManagerFactory) NodeExecutionJobManager(org.knime.core.node.workflow.NodeExecutionJobManager)

Example 3 with NodeExecutionJobManagerFactory

use of org.knime.core.node.workflow.NodeExecutionJobManagerFactory in project knime-core by knime.

the class NodeExecutionJobManagerPool method load.

/**
 * Restores a job manager given the parameters contained in the argument
 * settings.
 *
 * @param sncSettings To load from.
 * @return A customized job manager or the default one if no settings were
 *         stored.
 * @throws InvalidSettingsException If that fails.
 */
public static NodeExecutionJobManager load(final NodeSettingsRO sncSettings) throws InvalidSettingsException {
    String jobManagerID = sncSettings.getString(CFG_JOB_MANAGER_FACTORY_ID);
    NodeExecutionJobManagerFactory reference = getJobManagerFactory(jobManagerID);
    if (reference == null) {
        throw new InvalidSettingsException("Unknown job manager factory id \"" + jobManagerID + "\" (job manager factory possibly not installed?)");
    }
    NodeSettingsRO sub = sncSettings.getNodeSettings(CFG_JOB_MANAGER_SETTINGS);
    NodeExecutionJobManager jobManager = reference.getInstance();
    jobManager.load(sub);
    return jobManager;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) NodeExecutionJobManagerFactory(org.knime.core.node.workflow.NodeExecutionJobManagerFactory) ThreadNodeExecutionJobManagerFactory(org.knime.core.node.exec.ThreadNodeExecutionJobManagerFactory) NodeExecutionJobManager(org.knime.core.node.workflow.NodeExecutionJobManager)

Aggregations

ThreadNodeExecutionJobManagerFactory (org.knime.core.node.exec.ThreadNodeExecutionJobManagerFactory)3 NodeExecutionJobManagerFactory (org.knime.core.node.workflow.NodeExecutionJobManagerFactory)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 NodeExecutionJobManager (org.knime.core.node.workflow.NodeExecutionJobManager)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)1 NodeSettings (org.knime.core.node.NodeSettings)1 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)1 NodeContainerSettings (org.knime.core.node.workflow.NodeContainer.NodeContainerSettings)1 ThreadPool (org.knime.core.util.ThreadPool)1