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);
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations