Search in sources :

Example 1 with ActionExecutionException

use of org.pentaho.platform.api.engine.ActionExecutionException in project pentaho-platform by pentaho.

the class RuntimeContext method executeLoop.

private void executeLoop(final IActionParameter loopParm, final IPentahoResultSet loopSet, final IActionSequence sequence, final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async, boolean peekOnly) throws ActionSequenceException {
    // execute the actions
    int loopCount = -1;
    // to the first record. This is to resolve multiple levels of looping on resultset.
    if (loopSet.isScrollable()) {
        loopSet.beforeFirst();
    }
    if (peekOnly && !(loopSet instanceof IPeekable)) {
        throw new ActionExecutionException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "RuntimeContext.ERROR_0033_NOT_PEEKABLE"), session.getName(), instanceId, getActionSequence().getSequenceName(), null);
    }
    Object[] row = peekOnly ? ((IPeekable) loopSet).peek() : loopSet.next();
    Object[][] headerSet = loopSet.getMetaData().getColumnHeaders();
    // TODO handle OLAP result sets
    Object[] headers = headerSet[0];
    while (row != null) {
        loopCount++;
        if (RuntimeContext.debug) {
            debug(Messages.getInstance().getString("RuntimeContext.DEBUG_EXECUTING_ACTION", // $NON-NLS-1$
            Integer.toString(loopCount)));
        }
        if (execListener != null) {
            execListener.loop(this, loopCount);
        }
        if (loopParm != null) {
            IActionParameter ap;
            for (int columnNo = 0; columnNo < headers.length; columnNo++) {
                String name = headers[columnNo].toString();
                Object value = row[columnNo];
                String type = null;
                if (value instanceof String) {
                    type = IActionParameter.TYPE_STRING;
                } else if (value instanceof Date) {
                    type = IActionParameter.TYPE_DATE;
                } else if ((value instanceof Long) || (value instanceof Integer)) {
                    type = IActionParameter.TYPE_INTEGER;
                } else if ((value instanceof BigDecimal) || (value instanceof Double) || (value instanceof Float)) {
                    type = IActionParameter.TYPE_DECIMAL;
                } else if (value instanceof String[]) {
                    type = IActionParameter.TYPE_STRING;
                } else if (value == null) {
                    // $NON-NLS-1$
                    warn(Messages.getInstance().getString("RuntimeContext.WARN_VARIABLE_IN_LOOP_IS_NULL", name));
                } else {
                    type = IActionParameter.TYPE_OBJECT;
                    warn(Messages.getInstance().getString("RuntimeContext.WARN_VARIABLE_IN_LOOP_NOT_RECOGNIZED", name, // $NON-NLS-1$
                    value.getClass().toString()));
                }
                // TODO make sure any previous loop values are removed
                ap = paramManager.getInput(name);
                if (ap == null) {
                    ap = new ActionParameter(name, type, value, null, null);
                    addInputParameter(name, ap);
                } else {
                    ap.dispose();
                    ap.setValue(value);
                }
            }
        }
        try {
            performActions(sequence, doneListener, execListener, async);
        } catch (ActionSequenceException e) {
            e.setLoopIndex(loopCount);
            throw e;
        }
        row = peekOnly ? ((IPeekable) loopSet).peek() : loopSet.next();
    }
    status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) ActionParameter(org.pentaho.platform.engine.services.actionsequence.ActionParameter) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) Date(java.util.Date) BigDecimal(java.math.BigDecimal) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IPeekable(org.pentaho.commons.connection.IPeekable)

Example 2 with ActionExecutionException

use of org.pentaho.platform.api.engine.ActionExecutionException in project pentaho-platform by pentaho.

the class RuntimeContext method performActions.

private void performActions(final IActionSequence sequence, final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async) throws ActionSequenceException {
    IConditionalExecution conditional = sequence.getConditionalExecution();
    if (conditional != null) {
        try {
            if (!conditional.shouldExecute(paramManager.getAllParameters(), RuntimeContext.logger)) {
                // audit(MessageTypes.ACTION_SEQUENCE_EXECUTE_CONDITIONAL, MessageTypes.NOT_EXECUTED, "", 0); //$NON-NLS-1$ //$NON-NLS-2$
                if (RuntimeContext.debug) {
                    // $NON-NLS-1$
                    this.debug(Messages.getInstance().getString("RuntimeContext.INFO_ACTION_NOT_EXECUTED"));
                }
                status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
                return;
            }
        } catch (Exception ex) {
            // $NON-NLS-1$
            currentComponent = "";
            status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
            throw new ActionExecutionException(Messages.getInstance().getErrorString(// $NON-NLS-1$
            "RuntimeContext.ERROR_0032_CONDITIONAL_EXECUTION_FAILED"), // $NON-NLS-1$
            ex, session.getName(), instanceId, getActionSequence().getSequenceName(), null);
        }
    }
    List defList = sequence.getActionDefinitionsAndSequences();
    Object listItem;
    for (Iterator actIt = defList.iterator(); actIt.hasNext(); ) {
        listItem = actIt.next();
        if (listItem instanceof IActionSequence) {
            executeSequence((IActionSequence) listItem, doneListener, execListener, async);
        } else if (listItem instanceof ISolutionActionDefinition) {
            ISolutionActionDefinition actionDef = (ISolutionActionDefinition) listItem;
            currentComponent = actionDef.getComponentName();
            paramManager.setCurrentParameters(actionDef);
            try {
                executeAction(actionDef, parameterProviders, doneListener, execListener, async);
                paramManager.addOutputParameters(actionDef);
            } catch (ActionSequenceException ex) {
                // $NON-NLS-1$
                currentComponent = "";
                status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
                throw ex;
            }
        }
        if (promptStatus == IRuntimeContext.PROMPT_NOW) {
            break;
        }
        // $NON-NLS-1$
        currentComponent = "";
    }
    status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) IActionSequence(org.pentaho.platform.api.engine.IActionSequence) ISolutionActionDefinition(org.pentaho.platform.api.engine.ISolutionActionDefinition) IConditionalExecution(org.pentaho.platform.api.engine.IConditionalExecution) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) InvalidParameterException(org.pentaho.platform.api.engine.InvalidParameterException) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) ActionInitializationException(org.pentaho.platform.api.engine.ActionInitializationException) ActionSequencePromptException(org.pentaho.platform.api.engine.ActionSequencePromptException) FileNotFoundException(java.io.FileNotFoundException) XmlParseException(org.pentaho.platform.api.util.XmlParseException) UnresolvedParameterException(org.pentaho.platform.api.engine.UnresolvedParameterException) PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) IOException(java.io.IOException)

Example 3 with ActionExecutionException

use of org.pentaho.platform.api.engine.ActionExecutionException in project pentaho-platform by pentaho.

the class RuntimeContext method executeAction.

private void executeAction(final ISolutionActionDefinition actionDefinition, final Map pParameterProviders, final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async) throws ActionInitializationException, ActionExecutionException, UnresolvedParameterException {
    this.parameterProviders = pParameterProviders;
    // TODO get audit setting from action definition
    long start = new Date().getTime();
    if (audit) {
        // $NON-NLS-1$
        audit(MessageTypes.COMPONENT_EXECUTE_START, MessageTypes.START, "", 0);
    }
    try {
        // resolve the parameters
        resolveParameters();
    } catch (UnresolvedParameterException ex) {
        audit(MessageTypes.COMPONENT_EXECUTE_FAILED, MessageTypes.VALIDATION, Messages.getInstance().getErrorString("RuntimeContext.ERROR_0013_BAD_PARAMETERS"), // $NON-NLS-1$
        0);
        if (doneListener != null) {
            doneListener.actionComplete(this);
        }
        status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
        ex.setActionClass(actionDefinition.getComponentName());
        ex.setStepDescription(actionDefinition.getDescription());
        throw ex;
    }
    status = IRuntimeContext.RUNTIME_CONTEXT_RESOLVE_OK;
    if (RuntimeContext.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RuntimeContext.DEBUG_PRE-EXECUTE_AUDIT"));
    }
    List auditPre = actionDefinition.getPreExecuteAuditList();
    audit(auditPre);
    // initialize the component
    IComponent component = actionDefinition.getComponent();
    if (RuntimeContext.debug) {
        debug(Messages.getInstance().getString("RuntimeContext.DEBUG_SETTING_LOGGING", // $NON-NLS-1$
        Logger.getLogLevelName(loggingLevel)));
    }
    component.setLoggingLevel(loggingLevel);
    if (RuntimeContext.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RuntimeContext.DEBUG_INITIALIZING_COMPONENT"));
    }
    boolean initResult = false;
    try {
        initResult = component.init();
    /*
       * We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
       * contextual information, including the root cause. Allowing unchecked exceptions to pass through would
       * prevent valuable feedback in the log or response.
       */
    } catch (Throwable t) {
        throw new ActionInitializationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "RuntimeContext.ERROR_0016_COMPONENT_INITIALIZE_FAILED"), // $NON-NLS-1$
        t, session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
    }
    if (!initResult) {
        status = IRuntimeContext.RUNTIME_STATUS_INITIALIZE_FAIL;
        audit(MessageTypes.COMPONENT_EXECUTE_FAILED, MessageTypes.VALIDATION, Messages.getInstance().getErrorString("RuntimeContext.ERROR_0016_COMPONENT_INITIALIZE_FAILED"), // $NON-NLS-1$
        0);
        if (doneListener != null) {
            doneListener.actionComplete(this);
        }
        throw new ActionInitializationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "RuntimeContext.ERROR_0016_COMPONENT_INITIALIZE_FAILED"), session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
    }
    try {
        executeComponent(actionDefinition);
    } catch (ActionExecutionException ex) {
        if (doneListener != null) {
            doneListener.actionComplete(this);
        }
        throw ex;
    }
    if (RuntimeContext.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RuntimeContext.DEBUG_POST-EXECUTE_AUDIT"));
    }
    List auditPost = actionDefinition.getPostExecuteAuditList();
    audit(auditPost);
    if (audit) {
        long end = new Date().getTime();
        // $NON-NLS-1$
        audit(MessageTypes.COMPONENT_EXECUTE_END, MessageTypes.END, "", (int) (end - start));
    }
    if (doneListener != null) {
        doneListener.actionComplete(this);
    }
    if (execListener != null) {
        execListener.action(this, actionDefinition);
    }
}
Also used : UnresolvedParameterException(org.pentaho.platform.api.engine.UnresolvedParameterException) ActionInitializationException(org.pentaho.platform.api.engine.ActionInitializationException) IComponent(org.pentaho.platform.api.engine.IComponent) List(java.util.List) ArrayList(java.util.ArrayList) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) Date(java.util.Date)

Example 4 with ActionExecutionException

use of org.pentaho.platform.api.engine.ActionExecutionException in project pdi-platform-plugin by pentaho.

the class PdiAction method connectToRepository.

/**
 * Connects to the PDI repository
 *
 * @param logWriter
 * @return
 * @throws KettleException
 * @throws KettleSecurityException
 * @throws ActionExecutionException
 */
protected Repository connectToRepository(final LogWriter logWriter) throws KettleSecurityException, KettleException, ActionExecutionException {
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_META_REPOSITORY"));
    }
    RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_POPULATING_META"));
    }
    boolean singleDiServerInstance = // $NON-NLS-1$ //$NON-NLS-2$
    "true".equals(PentahoSystem.getSystemSetting(SINGLE_DI_SERVER_INSTANCE, "true"));
    try {
        if (singleDiServerInstance) {
            if (log.isDebugEnabled()) {
                // $NON-NLS-1$
                log.debug("singleDiServerInstance=true, loading default repository");
            }
            // only load a default enterprise repository. If this option is set, then you cannot load
            // transformations or jobs from anywhere but the local server.
            String repositoriesXml = // $NON-NLS-1$
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><repositories>" + // $NON-NLS-1$
            "<repository><id>PentahoEnterpriseRepository</id>" + "<name>" + SINGLE_DI_SERVER_INSTANCE + // $NON-NLS-1$ //$NON-NLS-2$
            "</name>" + "<description>" + SINGLE_DI_SERVER_INSTANCE + // $NON-NLS-1$ //$NON-NLS-2$
            "</description>" + "<repository_location_url>" + PentahoSystem.getApplicationContext().getFullyQualifiedServerURL() + // $NON-NLS-1$ //$NON-NLS-2$
            "</repository_location_url>" + // $NON-NLS-1$
            "<version_comment_mandatory>N</version_comment_mandatory>" + // $NON-NLS-1$
            "</repository>" + // $NON-NLS-1$
            "</repositories>";
            ByteArrayInputStream sbis = new ByteArrayInputStream(repositoriesXml.getBytes("UTF8"));
            repositoriesMeta.readDataFromInputStream(sbis);
        } else {
            // TODO: add support for specified repositories.xml files...
            // Read from the default $HOME/.kettle/repositories.xml file.
            repositoriesMeta.readData();
        }
    } catch (Exception e) {
        throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0018_META_REPOSITORY_NOT_POPULATED"), // $NON-NLS-1$
        e);
    }
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_FINDING_REPOSITORY"));
    }
    // Find the specified repository.
    RepositoryMeta repositoryMeta = null;
    try {
        if (singleDiServerInstance) {
            repositoryMeta = repositoriesMeta.findRepository(SINGLE_DI_SERVER_INSTANCE);
        } else {
            repositoryMeta = repositoriesMeta.findRepository(repositoryName);
        }
    } catch (Exception e) {
        throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0004_REPOSITORY_NOT_FOUND", repositoryName), // $NON-NLS-1$
        e);
    }
    if (repositoryMeta == null) {
        if (log.isDebugEnabled()) {
            log.debug(pdiUserAppender.getBuffer().toString());
        }
        throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0004_REPOSITORY_NOT_FOUND", // $NON-NLS-1$
        repositoryName));
    }
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_GETTING_REPOSITORY"));
    }
    Repository repository = null;
    try {
        repository = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta.getId(), Repository.class);
        repository.init(repositoryMeta);
    } catch (Exception e) {
        throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0016_COULD_NOT_GET_REPOSITORY_INSTANCE"), // $NON-NLS-1$
        e);
    }
    // OK, now try the username and password
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_CONNECTING"));
    }
    // Two scenarios here: internal to server or external to server. If internal, you are already authenticated. If
    // external, you must provide a username and additionally specify that the IP address of the machine running this
    // code is trusted.
    repository.connect(PentahoSessionHolder.getSession().getName(), "password");
    // OK, the repository is open and ready to use.
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_FINDING_DIRECTORY"));
    }
    return repository;
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Repository(org.pentaho.di.repository.Repository) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) FileNotFoundException(java.io.FileNotFoundException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException)

Example 5 with ActionExecutionException

use of org.pentaho.platform.api.engine.ActionExecutionException in project pdi-platform-plugin by pentaho.

the class PdiAction method createJobMeta.

private JobMeta createJobMeta(Repository repository, LogWriter logWriter) throws ActionExecutionException {
    // TODO: do we need to set a parameter on the job or trans meta called
    // ${pentaho.solutionpath} to mimic the old in-line xml replacement behavior
    // (see scm history for an illustration of this)?
    // TODO: beware of BISERVER-50
    EngineMetaLoader engineMetaUtil = new EngineMetaLoader(repository);
    JobMeta jobMeta;
    try {
        jobMeta = engineMetaUtil.loadJobMeta(directory, job);
    } catch (FileNotFoundException e) {
        throw new ActionExecutionException(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString("PdiAction.ERROR_0007_FAILED_JOBMETA_CREATION", directory, job), // $NON-NLS-1$
        e);
    }
    if (arguments != null) {
        jobMeta.setArguments(arguments);
    }
    if (logLevel != null) {
        jobMeta.setLogLevel(LogLevel.getLogLevelForCode(logLevel));
    }
    populateInputs(jobMeta, jobMeta);
    return jobMeta;
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) FileNotFoundException(java.io.FileNotFoundException) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException)

Aggregations

ActionExecutionException (org.pentaho.platform.api.engine.ActionExecutionException)10 FileNotFoundException (java.io.FileNotFoundException)6 ActionValidationException (org.pentaho.platform.api.engine.ActionValidationException)4 KettleException (org.pentaho.di.core.exception.KettleException)3 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)3 KettleStepException (org.pentaho.di.core.exception.KettleStepException)3 KettleValueException (org.pentaho.di.core.exception.KettleValueException)3 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)3 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 List (java.util.List)2 JobMeta (org.pentaho.di.job.JobMeta)2 StringObjectId (org.pentaho.di.repository.StringObjectId)2 TransMeta (org.pentaho.di.trans.TransMeta)2 ActionInitializationException (org.pentaho.platform.api.engine.ActionInitializationException)2 ActionSequenceException (org.pentaho.platform.api.engine.ActionSequenceException)2 UnresolvedParameterException (org.pentaho.platform.api.engine.UnresolvedParameterException)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1