Search in sources :

Example 1 with ErrorInfo

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

the class ItemImplementation method handleError.

/**
 * @param agentId
 * @param delegateId
 * @param stepPath
 * @param ex
 * @return
 * @throws PersistencyException
 * @throws ObjectNotFoundException
 * @throws AccessRightsException
 * @throws InvalidTransitionException
 * @throws InvalidDataException
 * @throws ObjectAlreadyExistsException
 * @throws InvalidCollectionModification
 */
private String handleError(SystemKey agentId, SystemKey delegateId, String stepPath, Workflow lifeCycle, Exception ex) throws PersistencyException, ObjectNotFoundException, AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException, InvalidCollectionModification {
    if (!Gateway.getProperties().getBoolean("StateMachine.enableErrorHandling", false))
        return null;
    int errorTransId = ((Activity) lifeCycle.search(stepPath)).getErrorTransitionId();
    if (errorTransId == -1)
        return null;
    try {
        AgentPath agent = new AgentPath(agentId);
        AgentPath delegate = delegateId == null ? null : new AgentPath(delegateId);
        String errorOutcome = Gateway.getMarshaller().marshall(new ErrorInfo(ex));
        lifeCycle.requestAction(agent, delegate, stepPath, mItemPath, errorTransId, errorOutcome);
        if (!(stepPath.startsWith("workflow/predefined")))
            mStorage.put(mItemPath, lifeCycle, lifeCycle);
        return errorOutcome;
    } catch (InvalidAgentPathException | ObjectCannotBeUpdated | CannotManageException | MarshalException | ValidationException | IOException | MappingException e) {
        Logger.error(e);
        return "";
    }
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ErrorInfo(org.cristalise.kernel.scripting.ErrorInfo) Activity(org.cristalise.kernel.lifecycle.instance.Activity) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) IOException(java.io.IOException) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) MappingException(org.exolab.castor.mapping.MappingException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException)

Example 2 with ErrorInfo

use of org.cristalise.kernel.scripting.ErrorInfo 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 3 with ErrorInfo

use of org.cristalise.kernel.scripting.ErrorInfo 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)

Aggregations

ErrorInfo (org.cristalise.kernel.scripting.ErrorInfo)3 ScriptingEngineException (org.cristalise.kernel.scripting.ScriptingEngineException)2 IOException (java.io.IOException)1 Date (java.util.Date)1 CannotManageException (org.cristalise.kernel.common.CannotManageException)1 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)1 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)1 Activity (org.cristalise.kernel.lifecycle.instance.Activity)1 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)1 AgentPath (org.cristalise.kernel.lookup.AgentPath)1 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)1 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)1 ScriptErrorException (org.cristalise.kernel.scripting.ScriptErrorException)1 MappingException (org.exolab.castor.mapping.MappingException)1 MarshalException (org.exolab.castor.xml.MarshalException)1 ValidationException (org.exolab.castor.xml.ValidationException)1