Search in sources :

Example 1 with HopWorkflowException

use of org.apache.hop.core.exception.HopWorkflowException in project hop by apache.

the class SftpClient method createFolder.

/**
 * Creates the given folder. The {@param path} can be either absolute or relative. Allows creation
 * of nested folders.
 */
public void createFolder(String path) throws HopWorkflowException {
    try {
        String[] folders = path.split("/");
        folders[0] = (path.charAt(0) != '/' ? pwd() + "/" : "") + folders[0];
        for (int i = 1; i < folders.length; i++) {
            folders[i] = folders[i - 1] + "/" + folders[i];
        }
        for (String f : folders) {
            if (f.length() != 0 && !folderExists(f)) {
                c.mkdir(f);
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new HopWorkflowException(e);
    } catch (SftpException e) {
        throw new HopWorkflowException(e);
    }
}
Also used : HopWorkflowException(org.apache.hop.core.exception.HopWorkflowException)

Example 2 with HopWorkflowException

use of org.apache.hop.core.exception.HopWorkflowException in project hop by apache.

the class Workflow method executeFromStart.

/**
 * Execute a workflow without previous results. This is an action point (not recursive)<br>
 * <br>
 *
 * @return the result of the execution
 * @throws HopException
 */
private Result executeFromStart() throws HopException {
    try {
        log.snap(Metrics.METRIC_WORKFLOW_START);
        setFinished(false);
        setStopped(false);
        HopEnvironment.setExecutionInformation(this);
        log.logBasic(BaseMessages.getString(PKG, "Workflow.Comment.WorkflowStarted"));
        ExtensionPointHandler.callExtensionPoint(log, this, HopExtensionPoint.WorkflowStart.id, this);
        // Start the tracking...
        ActionResult jerStart = new ActionResult(null, null, BaseMessages.getString(PKG, "Workflow.Comment.WorkflowStarted"), BaseMessages.getString(PKG, "Workflow.Reason.Started"), null, null);
        workflowTracker.addWorkflowTracker(new WorkflowTracker(workflowMeta, jerStart));
        setActive(true);
        // Where do we start?
        ActionMeta startpoint;
        // synchronize this to a parent workflow if needed.
        // 
        Object syncObject = this;
        if (parentWorkflow != null) {
            // parallel execution in a workflow
            syncObject = parentWorkflow;
        }
        synchronized (syncObject) {
            beginProcessing();
        }
        Result res = null;
        if (startActionMeta == null) {
            startpoint = workflowMeta.findStart();
        } else {
            startpoint = startActionMeta;
            res = startActionResult;
        }
        if (startpoint == null) {
            throw new HopWorkflowException(BaseMessages.getString(PKG, "Workflow.Log.CounldNotFindStartingPoint"));
        }
        ActionResult jerEnd = null;
        if (startpoint.isStart()) {
            // Perform optional looping in the special Start action...
            // 
            boolean isFirst = true;
            // Use a result obj coming from input otherwise init an empty Result object
            Result inputRes = null;
            if (result != null) {
                inputRes = result;
            } else {
                inputRes = new Result();
            }
            // Perhaps there is already a list of input rows available?
            if (getSourceRows() != null) {
                inputRes.setRows(getSourceRows());
            }
            ActionStart jes = (ActionStart) startpoint.getAction();
            while ((jes.isRepeat() || isFirst) && !isStopped()) {
                isFirst = false;
                res = executeFromStart(0, inputRes, startpoint, null, BaseMessages.getString(PKG, "Workflow.Reason.Started"));
            }
            jerEnd = new ActionResult(res, jes.getLogChannelId(), BaseMessages.getString(PKG, "Workflow.Comment.WorkflowFinished"), BaseMessages.getString(PKG, "Workflow.Reason.Finished"), null, null);
        } else {
            res = executeFromStart(0, res, startpoint, null, BaseMessages.getString(PKG, "Workflow.Reason.Started"));
            jerEnd = new ActionResult(res, startpoint.getAction().getLogChannel().getLogChannelId(), BaseMessages.getString(PKG, "Workflow.Comment.WorkflowFinished"), BaseMessages.getString(PKG, "Workflow.Reason.Finished"), null, null);
        }
        // Save this result...
        workflowTracker.addWorkflowTracker(new WorkflowTracker(workflowMeta, jerEnd));
        log.logBasic(BaseMessages.getString(PKG, "Workflow.Comment.WorkflowFinished"));
        setActive(false);
        if (!isStopped()) {
            setFinished(true);
        }
        return res;
    } finally {
        log.snap(Metrics.METRIC_WORKFLOW_STOP);
    }
}
Also used : ActionMeta(org.apache.hop.workflow.action.ActionMeta) HopWorkflowException(org.apache.hop.core.exception.HopWorkflowException) WorkflowTracker(org.apache.hop.core.gui.WorkflowTracker) FileObject(org.apache.commons.vfs2.FileObject) ActionStart(org.apache.hop.workflow.actions.start.ActionStart)

Example 3 with HopWorkflowException

use of org.apache.hop.core.exception.HopWorkflowException in project hop by apache.

the class Workflow method executeFromStart.

/**
 * Execute a workflow with previous results passed in.<br>
 * <br>
 * Execute called by ActionWorkflow: don't clear the actionResults.
 *
 * @param nr The action number
 * @param result the result of the previous execution
 * @return Result of the workflow execution
 * @throws HopWorkflowException
 */
public Result executeFromStart(int nr, Result result) throws HopException {
    setFinished(false);
    setActive(true);
    setInitialized(true);
    HopEnvironment.setExecutionInformation(this);
    // Where do we start?
    ActionMeta startpoint;
    // Perhaps there is already a list of input rows available?
    if (getSourceRows() != null) {
        result.setRows(getSourceRows());
    }
    startpoint = workflowMeta.findStart();
    if (startpoint == null) {
        throw new HopWorkflowException(BaseMessages.getString(PKG, "Workflow.Log.CounldNotFindStartingPoint"));
    }
    ActionStart jes = (ActionStart) startpoint.getAction();
    Result res;
    do {
        res = executeFromStart(nr, result, startpoint, null, BaseMessages.getString(PKG, "Workflow.Reason.StartOfAction"));
        setActive(false);
    } while (jes.isRepeat() && !isStopped());
    return res;
}
Also used : ActionMeta(org.apache.hop.workflow.action.ActionMeta) HopWorkflowException(org.apache.hop.core.exception.HopWorkflowException) ActionStart(org.apache.hop.workflow.actions.start.ActionStart)

Example 4 with HopWorkflowException

use of org.apache.hop.core.exception.HopWorkflowException in project hop by apache.

the class ActionStart method execute.

@Override
public Result execute(Result previousResult, int nr) throws HopWorkflowException {
    Result result = previousResult;
    try {
        long sleepTime = getNextExecutionTime();
        if (sleepTime > 0) {
            parentWorkflow.getLogChannel().logBasic(parentWorkflow.getWorkflowName(), "Sleeping: " + (sleepTime / 1000 / 60) + " minutes (sleep time=" + sleepTime + ")");
            long totalSleep = 0L;
            while (totalSleep < sleepTime && !parentWorkflow.isStopped()) {
                Thread.sleep(1000L);
                totalSleep += 1000L;
            }
        }
    } catch (InterruptedException e) {
        throw new HopWorkflowException(e);
    }
    result = previousResult;
    result.setResult(true);
    return result;
}
Also used : HopWorkflowException(org.apache.hop.core.exception.HopWorkflowException) ICheckResult(org.apache.hop.core.ICheckResult) Result(org.apache.hop.core.Result)

Example 5 with HopWorkflowException

use of org.apache.hop.core.exception.HopWorkflowException in project hop by apache.

the class ActionSetVariables method execute.

@Override
public Result execute(Result result, int nr) throws HopException {
    result.setResult(true);
    result.setNrErrors(0);
    try {
        List<String> variables = new ArrayList<>();
        List<String> variableValues = new ArrayList<>();
        List<Integer> variableTypes = new ArrayList<>();
        String realFilename = resolve(filename);
        if (!Utils.isEmpty(realFilename)) {
            try (InputStream is = HopVfs.getInputStream(realFilename);
                // for UTF8 properties files
                InputStreamReader isr = new InputStreamReader(is, "UTF-8");
                BufferedReader reader = new BufferedReader(isr)) {
                Properties properties = new Properties();
                properties.load(reader);
                for (Object key : properties.keySet()) {
                    variables.add((String) key);
                    variableValues.add((String) properties.get(key));
                    variableTypes.add(fileVariableType);
                }
            } catch (Exception e) {
                throw new HopException(BaseMessages.getString(PKG, "ActionSetVariables.Error.UnableReadPropertiesFile", realFilename));
            }
        }
        if (variableName != null) {
            for (int i = 0; i < variableName.length; i++) {
                variables.add(variableName[i]);
                variableValues.add(variableValue[i]);
                variableTypes.add(variableType[i]);
            }
        }
        // ones
        if (parentWorkflow != null) {
            for (String key : getEntryTransformSetVariablesMap().keySet()) {
                String parameterValue = parentWorkflow.getParameterValue(key);
                // value to ""
                if (parameterValue == null) {
                    parentWorkflow.setVariable(key, "");
                    setVariable(key, "");
                } else {
                    // if it is a parameter, then get the initial saved value of parent -  saved in
                    // entryTransformSetVariables Map
                    parentWorkflow.setVariable(key, getEntryTransformSetVariable(key));
                    setVariable(key, getEntryTransformSetVariable(key));
                }
            }
        }
        for (int i = 0; i < variables.size(); i++) {
            String varname = variables.get(i);
            String value = variableValues.get(i);
            int type = variableTypes.get(i);
            if (replaceVars) {
                varname = resolve(varname);
                value = resolve(value);
            }
            // OK, where do we set this value...
            switch(type) {
                case VARIABLE_TYPE_JVM:
                    if (value != null) {
                        System.setProperty(varname, value);
                    } else {
                        System.clearProperty(varname);
                    }
                    setVariable(varname, value);
                    IWorkflowEngine<WorkflowMeta> parentWorkflowTraverse = parentWorkflow;
                    while (parentWorkflowTraverse != null) {
                        parentWorkflowTraverse.setVariable(varname, value);
                        parentWorkflowTraverse = parentWorkflowTraverse.getParentWorkflow();
                    }
                    break;
                case VARIABLE_TYPE_ROOT_WORKFLOW:
                    // set variable in this action
                    setVariable(varname, value);
                    IWorkflowEngine<WorkflowMeta> rootWorkflow = parentWorkflow;
                    while (rootWorkflow != null) {
                        rootWorkflow.setVariable(varname, value);
                        rootWorkflow = rootWorkflow.getParentWorkflow();
                    }
                    break;
                case VARIABLE_TYPE_CURRENT_WORKFLOW:
                    setVariable(varname, value);
                    if (parentWorkflow != null) {
                        String parameterValue = parentWorkflow.getParameterValue(varname);
                        // if not a parameter, set the value
                        if (parameterValue == null) {
                            setEntryTransformSetVariable(varname, value);
                        } else {
                            // in future calls
                            if (parameterValue != null && parameterValue != value && !entryTransformSetVariablesMap.containsKey(varname)) {
                                setEntryTransformSetVariable(varname, parameterValue);
                            }
                        }
                        parentWorkflow.setVariable(varname, value);
                    } else {
                        throw new HopWorkflowException(BaseMessages.getString(PKG, "ActionSetVariables.Error.UnableSetVariableCurrentWorkflow", varname));
                    }
                    break;
                case VARIABLE_TYPE_PARENT_WORKFLOW:
                    setVariable(varname, value);
                    if (parentWorkflow != null) {
                        parentWorkflow.setVariable(varname, value);
                        IWorkflowEngine<WorkflowMeta> gpWorkflow = parentWorkflow.getParentWorkflow();
                        if (gpWorkflow != null) {
                            gpWorkflow.setVariable(varname, value);
                        } else {
                            throw new HopWorkflowException(BaseMessages.getString(PKG, "ActionSetVariables.Error.UnableSetVariableParentWorkflow", varname));
                        }
                    } else {
                        throw new HopWorkflowException(BaseMessages.getString(PKG, "ActionSetVariables.Error.UnableSetVariableCurrentWorkflow", varname));
                    }
                    break;
                default:
                    break;
            }
            // ok we can process this line
            if (log.isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "ActionSetVariables.Log.SetVariableToValue", varname, value));
            }
        }
    } catch (Exception e) {
        result.setResult(false);
        result.setNrErrors(1);
        logError(BaseMessages.getString(PKG, "ActionSetVariables.UnExcpectedError", e.getMessage()));
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) HopException(org.apache.hop.core.exception.HopException) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) HopWorkflowException(org.apache.hop.core.exception.HopWorkflowException) Properties(java.util.Properties) HopException(org.apache.hop.core.exception.HopException) HopWorkflowException(org.apache.hop.core.exception.HopWorkflowException) HopXmlException(org.apache.hop.core.exception.HopXmlException) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) BufferedReader(java.io.BufferedReader)

Aggregations

HopWorkflowException (org.apache.hop.core.exception.HopWorkflowException)9 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 FileObject (org.apache.commons.vfs2.FileObject)2 ActionMeta (org.apache.hop.workflow.action.ActionMeta)2 ActionStart (org.apache.hop.workflow.actions.start.ActionStart)2 com.jcraft.jsch (com.jcraft.jsch)1 LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ICheckResult (org.apache.hop.core.ICheckResult)1 Result (org.apache.hop.core.Result)1 HopException (org.apache.hop.core.exception.HopException)1 HopFileException (org.apache.hop.core.exception.HopFileException)1 HopXmlException (org.apache.hop.core.exception.HopXmlException)1 WorkflowTracker (org.apache.hop.core.gui.WorkflowTracker)1 WorkflowMeta (org.apache.hop.workflow.WorkflowMeta)1