Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ public ExecProcess(

@Override
public boolean processRow() throws HopException {
Object[] r = getRow(); // Get row from input rowset & set row busy!
if (r == null) { // no more input to be expected...
// Get row from input rowset & set row busy!
Object[] r = getRow();
// no more input to be expected...
if (r == null) {
setOutputDone();
return false;
}
Expand Down Expand Up @@ -98,7 +100,7 @@ public boolean processRow() throws HopException {
execProcess(processString, processResult);
}

if (meta.isFailWhenNotSuccess() && processResult.getExistStatus() != 0) {
if (meta.isFailWhenNotSuccess() && processResult.getExitValue() != 0) {
String errorString = processResult.getErrorStream();
if (StringUtils.isEmpty(errorString)) {
errorString = processResult.getOutputStream();
Expand All @@ -114,10 +116,10 @@ public boolean processRow() throws HopException {
outputRow[rowIndex++] = processResult.getErrorStream();

// Add result field to input stream
outputRow[rowIndex] = processResult.getExistStatus();
outputRow[rowIndex] = processResult.getExitValue();

// add new values to the row.
putRow(data.outputRowMeta, outputRow); // copy row to output rowset(s)
// add new values to the row. copy row to output rowset(s)
putRow(data.outputRowMeta, outputRow);

if (isRowLevel()) {
logRowlevel(
Expand Down Expand Up @@ -198,6 +200,7 @@ public void stopRunning() throws HopException {
try {
waitForLatch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new HopException("Interrupted exception while kill the process", e);
}
}
Expand All @@ -215,7 +218,7 @@ private void execProcess(String[] process, ProcessResult processresult) throws H
// execute process
try {
if (!meta.isArgumentsInFields()) {
p = data.runtime.exec(process[0]);
p = data.runtime.exec(new String[] {process[0]});
} else {
p = data.runtime.exec(process);
}
Expand Down Expand Up @@ -302,7 +305,7 @@ private void execProcess(String[] process, ProcessResult processresult) throws H
ie);
}

processresult.setExistStatus(child.exitValue());
processresult.setExitValue(child.exitValue());
}
} catch (IOException ioe) {
throw new HopException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import org.apache.hop.core.CheckResult;
import org.apache.hop.core.ICheckResult;
import org.apache.hop.core.annotations.Transform;
Expand All @@ -35,6 +37,8 @@
import org.apache.hop.pipeline.transform.BaseTransformMeta;
import org.apache.hop.pipeline.transform.TransformMeta;

@Getter
@Setter
@Transform(
id = "ExecProcess",
image = "execprocess.svg",
Expand Down Expand Up @@ -68,7 +72,7 @@ public class ExecProcessMeta extends BaseTransformMeta<ExecProcess, ExecProcessD

/** Output Line Delimiter - defaults to empty string for backward compatibility */
@HopMetadataProperty(key = "outputlinedelimiter")
public String outputLineDelimiter = "";
private String outputLineDelimiter = "";

/** Whether arguments for the command are provided in input fields */
@HopMetadataProperty(key = "argumentsInFields")
Expand Down Expand Up @@ -196,6 +200,13 @@ public void check(
}
}

@Override
public boolean supportsErrorHandling() {
return failWhenNotSuccess;
}

@Getter
@Setter
public static final class EPField {
@HopMetadataProperty(key = "argumentFieldName")
private String name;
Expand All @@ -205,122 +216,5 @@ public EPField() {}
public EPField(EPField f) {
this.name = f.name;
}

/**
* Gets name
*
* @return value of name
*/
public String getName() {
return name;
}

/**
* Sets name
*
* @param name value of name
*/
public void setName(String name) {
this.name = name;
}
}

@Override
public boolean supportsErrorHandling() {
return failWhenNotSuccess;
}

public void setOutputLineDelimiter(String value) {
this.outputLineDelimiter = value;
}

public String getOutputLineDelimiter() {
return outputLineDelimiter;
}

public boolean isArgumentsInFields() {
return argumentsInFields;
}

public void setArgumentsInFields(boolean argumentsInFields) {
this.argumentsInFields = argumentsInFields;
}

public List<EPField> getArgumentFields() {
return argumentFields;
}

public void setArgumentFields(List<EPField> argumentFields) {
this.argumentFields = argumentFields;
}

/**
* @return Returns the processField.
*/
public String getProcessField() {
return processField;
}

/**
* @param processField The processField to set.
*/
public void setProcessField(String processField) {
this.processField = processField;
}

/**
* @return Returns the resultName.
*/
public String getResultFieldName() {
return resultFieldName;
}

/**
* @param errorFieldName The errorFieldName to set.
*/
public void setResultFieldName(String errorFieldName) {
this.resultFieldName = errorFieldName;
}

/**
* @return Returns the errorFieldName.
*/
public String getErrorFieldName() {
return errorFieldName;
}

/**
* @param errorFieldName The errorFieldName to set.
*/
public void setErrorFieldName(String errorFieldName) {
this.errorFieldName = errorFieldName;
}

/**
* @return Returns the exitvaluefieldname.
*/
public String getExitValueFieldName() {
return exitValueFieldName;
}

/**
* @param exitValueFieldName The exitValueFieldName to set.
*/
public void setExitValueFieldName(String exitValueFieldName) {
this.exitValueFieldName = exitValueFieldName;
}

/**
* @return Returns the failWhenNotSuccess.
*/
public boolean isFailWhenNotSuccess() {
return failWhenNotSuccess;
}

/**
* @param failWhenNotSuccess The failWhenNotSuccess to set.
*/
public void setFailWhenNotSuccess(boolean failWhenNotSuccess) {
this.failWhenNotSuccess = failWhenNotSuccess;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,19 @@

package org.apache.hop.pipeline.transforms.execprocess;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ProcessResult {
private String outputStream;
private String errorStream;
private long exitValue;

public ProcessResult() {
super();
this.outputStream = null;
this.errorStream = null;
this.exitValue = 1;
}

public String getOutputStream() {
return this.outputStream;
}

public void setOutputStream(String string) {
this.outputStream = string;
}

public String getErrorStream() {
return this.errorStream;
}

public void setErrorStream(String string) {
this.errorStream = string;
}

public long getExistStatus() {
return this.exitValue;
}

public void setExistStatus(long value) {
this.exitValue = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hop.pipeline.transforms.execprocess;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.List;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.row.RowMeta;
import org.apache.hop.pipeline.transform.ITransformData;
import org.junit.jupiter.api.Test;

/** Unit test for {@link ExecProcessData} */
class ExecProcessDataTest {

@Test
void constructorInitializesDefaults() {
ExecProcessData data = new ExecProcessData();

assertEquals(-1, data.indexOfProcess);
assertNull(data.argumentIndexes);
assertNull(data.outputRowMeta);
assertNull(data.runtime);
}

@Test
void implementsITransformData() {
ExecProcessData data = new ExecProcessData();
assertTrue(data instanceof ITransformData);
}

@Test
void fieldAssignmentsRoundTrip() {
ExecProcessData data = new ExecProcessData();

List<Integer> argumentIndexes = new ArrayList<>();
argumentIndexes.add(1);
argumentIndexes.add(3);
IRowMeta outputRowMeta = new RowMeta();
Runtime runtime = Runtime.getRuntime();

data.indexOfProcess = 2;
data.argumentIndexes = argumentIndexes;
data.outputRowMeta = outputRowMeta;
data.runtime = runtime;

assertEquals(2, data.indexOfProcess);
assertSame(argumentIndexes, data.argumentIndexes);
assertEquals(2, data.argumentIndexes.size());
assertEquals(1, data.argumentIndexes.get(0));
assertEquals(3, data.argumentIndexes.get(1));
assertSame(outputRowMeta, data.outputRowMeta);
assertNotNull(data.runtime);
assertSame(runtime, data.runtime);
}
}
Loading
Loading