Search in sources :

Example 1 with ScriptingEngineException

use of org.cristalise.kernel.scripting.ScriptingEngineException in project kernel by cristal-ise.

the class AgentProxy method execute.

/**
 * Standard execution of jobs. Note that this method should always be the one used from clients.
 * All execution parameters are taken from the job where they're probably going to be correct.
 *
 * @param job the Actual Job to be executed
 * @return The outcome after processing. May have been altered by the step.
 *
 * @throws AccessRightsException The agent was not allowed to execute this step
 * @throws InvalidDataException The parameters supplied were incorrect
 * @throws InvalidTransitionException The step wasn't available
 * @throws ObjectNotFoundException Thrown by some steps that try to locate additional objects
 * @throws PersistencyException Problem writing or reading the database
 * @throws ObjectAlreadyExistsException Thrown by steps that create additional object
 * @throws ScriptErrorException Thrown by scripting classes
 * @throws InvalidCollectionModification Thrown by steps that create/modify collections
 */
public String execute(Job job) throws AccessRightsException, InvalidDataException, InvalidTransitionException, ObjectNotFoundException, PersistencyException, ObjectAlreadyExistsException, ScriptErrorException, InvalidCollectionModification {
    ItemProxy item = Gateway.getProxyManager().getProxy(job.getItemPath());
    Date startTime = new Date();
    Logger.msg(3, "AgentProxy.execute(job) - act:" + job.getStepPath() + " agent:" + mAgentPath.getAgentName());
    if (job.hasScript()) {
        Logger.msg(3, "AgentProxy.execute(job) - executing script");
        try {
            // pre-validate outcome for script if there is one
            if (job.hasOutcome() && job.isOutcomeSet())
                job.getOutcome().validateAndCheck();
            // load script
            ErrorInfo scriptErrors = callScript(item, job);
            String errorString = scriptErrors.toString();
            if (scriptErrors.getFatal()) {
                Logger.error("AgentProxy.execute(job) - fatal script errors:" + scriptErrors);
                throw new ScriptErrorException(scriptErrors);
            }
            if (errorString.length() > 0)
                Logger.warning("Script errors: " + errorString);
        } catch (ScriptingEngineException ex) {
            Logger.error(ex);
            throw new InvalidDataException(ex.getMessage());
        }
    } else if (job.hasQuery() && !"Query".equals(job.getActProp(BuiltInVertexProperties.OUTCOME_INIT))) {
        Logger.msg(3, "AgentProxy.execute(job) - executing query (OutcomeInit != Query)");
        // pre-validate outcome for query if there is one
        if (job.hasOutcome() && job.isOutcomeSet())
            job.getOutcome().validateAndCheck();
        job.setOutcome(item.executeQuery(job.getQuery()));
    }
    if (job.hasOutcome() && job.isOutcomeSet())
        job.getOutcome().validateAndCheck();
    job.setAgentPath(mAgentPath);
    Logger.msg(3, "AgentProxy.execute(job) - submitting job to item proxy");
    String result = item.requestAction(job);
    if (Logger.doLog(3)) {
        Date timeNow = new Date();
        long secsNow = (timeNow.getTime() - startTime.getTime()) / 1000;
        Logger.msg(3, "AgentProxy.execute(job) - execution DONE in " + secsNow + " seconds");
    }
    return result;
}
Also used : ScriptErrorException(org.cristalise.kernel.scripting.ScriptErrorException) ScriptingEngineException(org.cristalise.kernel.scripting.ScriptingEngineException) ErrorInfo(org.cristalise.kernel.scripting.ErrorInfo) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Date(java.util.Date)

Example 2 with ScriptingEngineException

use of org.cristalise.kernel.scripting.ScriptingEngineException in project kernel by cristal-ise.

the class DependencyMember method evaluateScript.

/**
 * @return either PropertyArrayList or CastorHashMap
 *
 * @throws InvalidDataException
 * @throws ObjectNotFoundException
 */
protected Object evaluateScript() throws InvalidDataException, ObjectNotFoundException {
    Logger.msg(5, "DependencyMember.evaluateScript() - memberUUID:" + getChildUUID());
    Script script = LocalObjectLoader.getScript(getProperties());
    try {
        script.setInputParamValue("dependencyMember", this);
        script.setInputParamValue("storage", Gateway.getStorage());
        script.setInputParamValue("proxy", Gateway.getProxyManager());
        script.setInputParamValue("lookup", Gateway.getLookup());
        return script.evaluate(getItemPath(), getProperties(), null, null);
    } catch (ScriptingEngineException e) {
        Logger.error(e);
        throw new InvalidDataException(e.getMessage());
    }
}
Also used : Script(org.cristalise.kernel.scripting.Script) ScriptingEngineException(org.cristalise.kernel.scripting.ScriptingEngineException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 3 with ScriptingEngineException

use of org.cristalise.kernel.scripting.ScriptingEngineException in project kernel by cristal-ise.

the class Module method runScript.

public void runScript(String event, AgentProxy agent, boolean isServer) throws ScriptingEngineException {
    for (ModuleEmbeddedScript script : scripts) {
        if (script.shouldRun(event, isServer)) {
            Logger.msg("Running " + script.event + " " + script.target + " script from " + name);
            Object result = script.getScript(ns, agent).execute();
            if (result instanceof ErrorInfo) {
                ErrorInfo error = (ErrorInfo) result;
                Logger.error(error.toString());
                if (error.getFatal())
                    throw new ScriptingEngineException("Fatal Script Error");
            } else if (result != null) {
                Logger.msg(result.toString());
            }
        }
    }
}
Also used : ScriptingEngineException(org.cristalise.kernel.scripting.ScriptingEngineException) ErrorInfo(org.cristalise.kernel.scripting.ErrorInfo)

Example 4 with ScriptingEngineException

use of org.cristalise.kernel.scripting.ScriptingEngineException in project kernel by cristal-ise.

the class Split method calculateNexts.

public String[] calculateNexts(ItemPath itemPath, Object locker) throws InvalidDataException {
    String nexts;
    String expr = (String) getBuiltInProperty(ROUTING_EXPR);
    String scriptName = (String) getBuiltInProperty(ROUTING_SCRIPT_NAME);
    Integer scriptVersion = deriveVersionNumber(getBuiltInProperty(ROUTING_SCRIPT_VERSION));
    if (expr != null && expr.length() > 0) {
        try {
            nexts = (String) DataHelperUtility.evaluateValue(itemPath, expr, getActContext(), locker);
        } catch (Exception e) {
            Logger.error(e);
            throw new InvalidDataException("XORSplit expression evaulation failed: " + expr + " with " + e.getMessage());
        }
    } else if (scriptName != null && scriptName.length() > 0) {
        try {
            nexts = evaluateScript(scriptName, scriptVersion, itemPath, locker).toString();
        } catch (ScriptingEngineException e) {
            Logger.error(e);
            throw new InvalidDataException("Error running routing script " + scriptName + " v" + scriptVersion);
        }
    } else
        throw new InvalidDataException("Split is invalid without valid routing script or expression");
    StringTokenizer tok = new StringTokenizer(nexts, ",");
    String[] nextsTab = new String[tok.countTokens()];
    for (int i = 0; i < nextsTab.length; i++) nextsTab[i] = tok.nextToken();
    return nextsTab;
}
Also used : StringTokenizer(java.util.StringTokenizer) ScriptingEngineException(org.cristalise.kernel.scripting.ScriptingEngineException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ScriptingEngineException(org.cristalise.kernel.scripting.ScriptingEngineException)

Example 5 with ScriptingEngineException

use of org.cristalise.kernel.scripting.ScriptingEngineException in project kernel by cristal-ise.

the class ModuleManager method registerModules.

public void registerModules() throws ModuleException {
    ItemProxy serverItem;
    try {
        serverItem = Gateway.getProxyManager().getProxy(new DomainPath("/servers/" + Gateway.getProperties().getString("ItemServer.name")));
    } catch (ObjectNotFoundException e) {
        throw new ModuleException("Cannot find local server name.");
    }
    Logger.msg(3, "ModuleManager.registerModules() - Registering modules");
    boolean reset = Gateway.getProperties().getBoolean("Module.reset", false);
    for (Module thisMod : modules) {
        if (Bootstrap.shutdown)
            return;
        Logger.msg("ModuleManager.registerModules() - Registering module " + thisMod.getName());
        try {
            String thisResetKey = "Module." + thisMod.getNamespace() + ".reset";
            boolean thisReset = reset;
            if (Gateway.getProperties().containsKey(thisResetKey)) {
                thisReset = Gateway.getProperties().getBoolean(thisResetKey);
            }
            thisMod.setModuleXML(modulesXML.get(thisMod.getNamespace()));
            thisMod.importAll(serverItem, agent, thisReset);
        } catch (Exception e) {
            Logger.error(e);
            throw new ModuleException("Error importing items for module " + thisMod.getName());
        }
        Logger.msg("ModuleManager.registerModules() - Module " + thisMod.getName() + " registered");
        try {
            thisMod.runScript("startup", agent, true);
        } catch (ScriptingEngineException e) {
            Logger.error(e);
            throw new ModuleException("Error in startup script for module " + thisMod.getName());
        }
    }
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) ItemProxy(org.cristalise.kernel.entity.proxy.ItemProxy) ScriptingEngineException(org.cristalise.kernel.scripting.ScriptingEngineException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ScriptingEngineException(org.cristalise.kernel.scripting.ScriptingEngineException)

Aggregations

ScriptingEngineException (org.cristalise.kernel.scripting.ScriptingEngineException)5 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)4 ErrorInfo (org.cristalise.kernel.scripting.ErrorInfo)2 Date (java.util.Date)1 StringTokenizer (java.util.StringTokenizer)1 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)1 ItemProxy (org.cristalise.kernel.entity.proxy.ItemProxy)1 DomainPath (org.cristalise.kernel.lookup.DomainPath)1 Script (org.cristalise.kernel.scripting.Script)1 ScriptErrorException (org.cristalise.kernel.scripting.ScriptErrorException)1