use of org.apache.hop.core.parameters.DuplicateParamException in project hop by apache.
the class PipelineDialog method ok.
private void ok() {
boolean ok = true;
pipelineMeta.setName(wPipelineName.getText());
pipelineMeta.setNameSynchronizedWithFilename(wNameFilenameSync.getSelection());
pipelineMeta.setDescription(wPipelineDescription.getText());
pipelineMeta.setExtendedDescription(wExtendedDescription.getText());
pipelineMeta.setPipelineVersion(wPipelineVersion.getText());
if (wPipelineStatus.getSelectionIndex() != 2) {
pipelineMeta.setPipelineStatus(wPipelineStatus.getSelectionIndex() + 1);
} else {
pipelineMeta.setPipelineStatus(-1);
}
// Clear and add parameters
pipelineMeta.removeAllParameters();
int nrNonEmptyFields = wParamFields.nrNonEmpty();
for (int i = 0; i < nrNonEmptyFields; i++) {
TableItem item = wParamFields.getNonEmpty(i);
try {
pipelineMeta.addParameterDefinition(item.getText(1), item.getText(2), item.getText(3));
} catch (DuplicateParamException e) {
// Ignore the duplicate parameter.
}
}
// Performance monitoring tab:
//
pipelineMeta.setCapturingTransformPerformanceSnapShots(wEnableTransformPerfMonitor.getSelection());
pipelineMeta.setTransformPerformanceCapturingSizeLimit(wTransformPerfMaxSize.getText());
try {
long transformPerformanceCapturingDelay = Long.parseLong(wTransformPerfInterval.getText());
// values equal or less than zero cause problems during monitoring
if (transformPerformanceCapturingDelay <= 0 && pipelineMeta.isCapturingTransformPerformanceSnapShots()) {
throw new HopException();
} else {
if (transformPerformanceCapturingDelay <= 0) {
// Default to 1 second if transform performance monitoring is disabled
transformPerformanceCapturingDelay = 1000;
}
pipelineMeta.setTransformPerformanceCapturingDelay(transformPerformanceCapturingDelay);
}
} catch (Exception e) {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setText(BaseMessages.getString(PKG, "PipelineDialog.InvalidTransformPerfIntervalNumber.DialogTitle"));
mb.setMessage(BaseMessages.getString(PKG, "PipelineDialog.InvalidTransformPerfIntervalNumber.DialogMessage"));
mb.open();
wTransformPerfInterval.setFocus();
wTransformPerfInterval.selectAll();
ok = false;
}
for (IPipelineDialogPlugin extraTab : extraTabs) {
try {
extraTab.ok(pipelineMeta);
} catch (Exception e) {
new ErrorDialog(shell, "Error", "Error getting information from extra plugin tab", e);
}
}
if (ok) {
pipelineMeta.setChanged(changed || pipelineMeta.hasChanged());
dispose();
}
}
use of org.apache.hop.core.parameters.DuplicateParamException in project hop by apache.
the class ActionWorkflow method execute.
@Override
public Result execute(Result result, int nr) throws HopException {
result.setEntryNr(nr);
LogChannelFileWriter logChannelFileWriter = null;
LogLevel jobLogLevel = parentWorkflow.getLogLevel();
if (setLogfile) {
String realLogFilename = resolve(getLogFilename());
// if we do not have one, we must fail
if (Utils.isEmpty(realLogFilename)) {
logError(BaseMessages.getString(PKG, "ActionWorkflow.Exception.LogFilenameMissing"));
result.setNrErrors(1);
result.setResult(false);
return result;
}
// create parent folder?
if (!createParentFolder(realLogFilename)) {
result.setNrErrors(1);
result.setResult(false);
return result;
}
try {
logChannelFileWriter = new LogChannelFileWriter(this.getLogChannelId(), HopVfs.getFileObject(realLogFilename), setAppendLogfile);
logChannelFileWriter.startLogging();
} catch (HopException e) {
logError("Unable to open file appender for file [" + getLogFilename() + "] : " + e.toString());
logError(Const.getStackTracker(e));
result.setNrErrors(1);
result.setResult(false);
return result;
}
jobLogLevel = logFileLevel;
}
try {
// First load the workflow, outside of the loop...
if (parentWorkflow.getWorkflowMeta() != null) {
// reset the internal variables again.
// Maybe we should split up the variables even more like in UNIX shells.
// The internal variables need to be reset to be able use them properly
// in 2 sequential sub workflows.
parentWorkflow.getWorkflowMeta().setInternalHopVariables(this);
}
// Explain what we are loading...
//
logDetailed("Loading workflow from XML file : [" + resolve(filename) + "]");
WorkflowMeta workflowMeta = getWorkflowMeta(getMetadataProvider(), this);
//
if (workflowMeta == null) {
throw new HopException("Unable to load the workflow: please specify a filename");
}
verifyRecursiveExecution(parentWorkflow, workflowMeta);
int iteration = 0;
copyFrom(parentWorkflow);
setParentVariables(parentWorkflow);
RowMetaAndData resultRow = null;
boolean first = true;
List<RowMetaAndData> rows = new ArrayList<>(result.getRows());
while ((first && !execPerRow) || (execPerRow && rows != null && iteration < rows.size() && result.getNrErrors() == 0)) {
first = false;
//
if (execPerRow) {
result.getRows().clear();
}
if (rows != null && execPerRow) {
resultRow = rows.get(iteration);
} else {
resultRow = null;
}
INamedParameters namedParam = new NamedParameters();
//
if (paramsFromPrevious) {
String[] parentParameters = parentWorkflow.listParameters();
for (int idx = 0; idx < parentParameters.length; idx++) {
String par = parentParameters[idx];
String def = parentWorkflow.getParameterDefault(par);
String val = parentWorkflow.getParameterValue(par);
String des = parentWorkflow.getParameterDescription(par);
namedParam.addParameterDefinition(par, def, des);
namedParam.setParameterValue(par, val);
}
}
//
if (parameters != null) {
for (int idx = 0; idx < parameters.length; idx++) {
if (!Utils.isEmpty(parameters[idx])) {
//
if (Const.indexOfString(parameters[idx], namedParam.listParameters()) < 0) {
// We have a parameter
try {
namedParam.addParameterDefinition(parameters[idx], "", "Action runtime");
} catch (DuplicateParamException e) {
// Should never happen
//
logError("Duplicate parameter definition for " + parameters[idx]);
}
}
if (Utils.isEmpty(Const.trim(parameterFieldNames[idx]))) {
namedParam.setParameterValue(parameters[idx], Const.NVL(resolve(parameterValues[idx]), ""));
} else {
// something filled in, in the field column...
//
String value = "";
if (resultRow != null) {
value = resultRow.getString(parameterFieldNames[idx], "");
}
namedParam.setParameterValue(parameters[idx], value);
}
}
}
}
Result oneResult = new Result();
List<RowMetaAndData> sourceRows = null;
if (execPerRow) {
// Execute for each input row
// Just pass a single row
//
List<RowMetaAndData> newList = new ArrayList<>();
newList.add(resultRow);
sourceRows = newList;
if (paramsFromPrevious) {
if (parameters != null) {
for (int idx = 0; idx < parameters.length; idx++) {
if (!Utils.isEmpty(parameters[idx])) {
// We have a parameter
if (Utils.isEmpty(Const.trim(parameterFieldNames[idx]))) {
namedParam.setParameterValue(parameters[idx], Const.NVL(resolve(parameterValues[idx]), ""));
} else {
String fieldValue = "";
if (resultRow != null) {
fieldValue = resultRow.getString(parameterFieldNames[idx], "");
}
// Get the value from the input stream
namedParam.setParameterValue(parameters[idx], Const.NVL(fieldValue, ""));
}
}
}
}
}
} else {
// Keep it as it was...
//
sourceRows = result.getRows();
if (paramsFromPrevious) {
if (parameters != null) {
for (int idx = 0; idx < parameters.length; idx++) {
if (!Utils.isEmpty(parameters[idx])) {
// We have a parameter
if (Utils.isEmpty(Const.trim(parameterFieldNames[idx]))) {
namedParam.setParameterValue(parameters[idx], Const.NVL(resolve(parameterValues[idx]), ""));
} else {
String fieldValue = "";
if (resultRow != null) {
fieldValue = resultRow.getString(parameterFieldNames[idx], "");
}
// Get the value from the input stream
namedParam.setParameterValue(parameters[idx], Const.NVL(fieldValue, ""));
}
}
}
}
}
}
// Create a new workflow
//
workflow = WorkflowEngineFactory.createWorkflowEngine(this, resolve(runConfiguration), getMetadataProvider(), workflowMeta, this);
workflow.setParentWorkflow(parentWorkflow);
workflow.setLogLevel(jobLogLevel);
workflow.shareWith(this);
workflow.setResult(result);
workflow.setInternalHopVariables();
workflow.copyParametersFromDefinitions(workflowMeta);
workflow.setInteractive(parentWorkflow.isInteractive());
if (workflow.isInteractive()) {
workflow.getActionListeners().addAll(parentWorkflow.getActionListeners());
}
// Set the parameters calculated above on this instance.
//
workflow.clearParameterValues();
String[] parameterNames = workflow.listParameters();
for (int idx = 0; idx < parameterNames.length; idx++) {
// Grab the parameter value set in the action
//
String thisValue = namedParam.getParameterValue(parameterNames[idx]);
if (!Utils.isEmpty(thisValue)) {
// Set the value as specified by the user in the action
//
workflow.setParameterValue(parameterNames[idx], thisValue);
} else {
//
if (isPassingAllParameters()) {
String parentValue = parentWorkflow.getParameterValue(parameterNames[idx]);
if (!Utils.isEmpty(parentValue)) {
workflow.setParameterValue(parameterNames[idx], parentValue);
}
}
}
}
workflow.activateParameters(workflow);
// Set the source rows we calculated above...
//
workflow.setSourceRows(sourceRows);
// Link the workflow with the sub-workflow
parentWorkflow.getWorkflowTracker().addWorkflowTracker(workflow.getWorkflowTracker());
// Link both ways!
workflow.getWorkflowTracker().setParentWorkflowTracker(parentWorkflow.getWorkflowTracker());
ActionWorkflowRunner runner = new ActionWorkflowRunner(workflow, result, nr, log);
Thread workflowRunnerThread = new Thread(runner);
// added UUID to thread name, otherwise threads do share names if workflows actions are
// executed in parallel in a
// parent workflow
// if that happens, contained pipelines start closing each other's connections
workflowRunnerThread.setName(Const.NVL(workflow.getWorkflowMeta().getName(), workflow.getWorkflowMeta().getFilename()) + " UUID: " + UUID.randomUUID().toString());
workflowRunnerThread.start();
if (isWaitingToFinish()) {
//
while (!runner.isFinished() && !parentWorkflow.isStopped()) {
try {
Thread.sleep(0, 1);
} catch (InterruptedException e) {
// Ignore
}
}
// if the parent-workflow was stopped, stop the sub-workflow too...
if (parentWorkflow.isStopped()) {
workflow.stopExecution();
// Wait until finished!
runner.waitUntilFinished();
}
oneResult = runner.getResult();
// clear only the numbers, NOT the files or rows.
result.clear();
result.add(oneResult);
// Set the result rows too, if any ...
if (!Utils.isEmpty(oneResult.getRows())) {
result.setRows(new ArrayList<>(oneResult.getRows()));
}
//
if (oneResult.getResult() == false) {
result.setNrErrors(result.getNrErrors() + 1);
}
}
iteration++;
}
} catch (HopException ke) {
logError("Error running action 'workflow' : ", ke);
result.setResult(false);
result.setNrErrors(1L);
}
if (setLogfile) {
if (logChannelFileWriter != null) {
logChannelFileWriter.stopLogging();
ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_LOG, logChannelFileWriter.getLogFile(), parentWorkflow.getWorkflowName(), getName());
result.getResultFiles().put(resultFile.getFile().toString(), resultFile);
//
if (logChannelFileWriter.getException() != null) {
logError("Unable to open log file [" + getLogFilename() + "] : ");
logError(Const.getStackTracker(logChannelFileWriter.getException()));
result.setNrErrors(1);
result.setResult(false);
return result;
}
}
}
if (result.getNrErrors() > 0) {
result.setResult(false);
} else {
result.setResult(true);
}
return result;
}
Aggregations