use of org.apache.hop.core.exception.HopPluginException in project hop by apache.
the class InjectDataSetIntoTransformExtensionPoint method callExtensionPoint.
@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, final IPipelineEngine<PipelineMeta> pipeline) throws HopException {
if (!(pipeline instanceof LocalPipelineEngine)) {
throw new HopPluginException("Unit tests can only run using a local pipeline engine type");
}
final PipelineMeta pipelineMeta = pipeline.getPipelineMeta();
boolean dataSetEnabled = "Y".equalsIgnoreCase(pipeline.getVariable(DataSetConst.VAR_RUN_UNIT_TEST));
if (log.isDetailed()) {
log.logDetailed("Data Set enabled? " + dataSetEnabled);
}
if (!dataSetEnabled) {
return;
}
String unitTestName = pipeline.getVariable(DataSetConst.VAR_UNIT_TEST_NAME);
if (log.isDetailed()) {
log.logDetailed("Unit test name: " + unitTestName);
}
try {
IHopMetadataProvider metadataProvider = pipelineMeta.getMetadataProvider();
//
if (StringUtil.isEmpty(unitTestName)) {
return;
}
PipelineUnitTest unitTest = metadataProvider.getSerializer(PipelineUnitTest.class).load(unitTestName);
if (unitTest == null) {
if (log.isDetailed()) {
log.logDetailed("Unit test '" + unitTestName + "' could not be found");
}
return;
}
//
for (final TransformMeta transformMeta : pipeline.getPipelineMeta().getTransforms()) {
String transformName = transformMeta.getName();
PipelineUnitTestSetLocation inputLocation = unitTest.findInputLocation(transformName);
if (inputLocation != null && StringUtils.isNotEmpty(inputLocation.getDataSetName())) {
String inputDataSetName = inputLocation.getDataSetName();
log.logDetailed("Data Set location found for transform '" + transformName + "' and data set " + inputDataSetName);
// We need to inject data from the data set with the specified name into the transform
//
injectDataSetIntoTransform((LocalPipelineEngine) pipeline, inputDataSetName, metadataProvider, transformMeta, inputLocation);
}
// How about capturing rows for golden data review?
//
PipelineUnitTestSetLocation goldenLocation = unitTest.findGoldenLocation(transformName);
if (goldenLocation != null) {
String goldenDataSetName = goldenLocation.getDataSetName();
if (!StringUtil.isEmpty(goldenDataSetName)) {
log.logDetailed("Capturing rows for validation at pipeline end, transform='" + transformMeta.getName() + "', golden set '" + goldenDataSetName);
final RowCollection rowCollection = new RowCollection();
// Create a row collection map if it's missing...
//
@SuppressWarnings("unchecked") Map<String, RowCollection> collectionMap = (Map<String, RowCollection>) pipeline.getExtensionDataMap().get(DataSetConst.ROW_COLLECTION_MAP);
if (collectionMap == null) {
collectionMap = new HashMap<>();
pipeline.getExtensionDataMap().put(DataSetConst.ROW_COLLECTION_MAP, collectionMap);
}
// Keep the map for safe keeping...
//
collectionMap.put(transformMeta.getName(), rowCollection);
// We'll capture the rows from this one and then evaluate them after execution...
//
IEngineComponent component = pipeline.findComponent(transformMeta.getName(), 0);
component.addRowListener(new RowAdapter() {
@Override
public void rowReadEvent(IRowMeta rowMeta, Object[] row) throws HopTransformException {
if (rowCollection.getRowMeta() == null) {
rowCollection.setRowMeta(rowMeta);
}
rowCollection.getRows().add(row);
}
});
}
}
}
} catch (Throwable e) {
throw new HopException("Unable to inject data set rows", e);
}
}
use of org.apache.hop.core.exception.HopPluginException in project hop by apache.
the class CypherMeta method getFields.
@Override
public void getFields(IRowMeta rowMeta, String name, IRowMeta[] info, TransformMeta nextStep, IVariables space, IHopMetadataProvider metadataProvider) throws HopTransformException {
if (usingUnwind) {
// Unwind only outputs results, not input
//
rowMeta.clear();
}
if (returningGraph) {
// We send out a single Graph value per input row
//
IValueMeta valueMetaGraph = new ValueMetaGraph(Const.NVL(returnGraphField, "graph"));
valueMetaGraph.setOrigin(name);
rowMeta.addValueMeta(valueMetaGraph);
} else {
//
for (ReturnValue returnValue : returnValues) {
try {
int type = ValueMetaFactory.getIdForValueMeta(returnValue.getType());
IValueMeta valueMeta = ValueMetaFactory.createValueMeta(returnValue.getName(), type);
valueMeta.setOrigin(name);
rowMeta.addValueMeta(valueMeta);
} catch (HopPluginException e) {
throw new HopTransformException("Unknown data type '" + returnValue.getType() + "' for value named '" + returnValue.getName() + "'");
}
}
}
}
use of org.apache.hop.core.exception.HopPluginException in project hop by apache.
the class PipelineExecutorMeta method addFieldToRow.
protected void addFieldToRow(IRowMeta row, String fieldName, int type, int length, int precision) throws HopTransformException {
if (!Utils.isEmpty(fieldName)) {
try {
IValueMeta value = ValueMetaFactory.createValueMeta(fieldName, type, length, precision);
value.setOrigin(getParentTransformMeta().getName());
row.addValueMeta(value);
} catch (HopPluginException e) {
throw new HopTransformException(BaseMessages.getString(PKG, "PipelineExecutorMeta.ValueMetaInterfaceCreation", fieldName), e);
}
}
}
use of org.apache.hop.core.exception.HopPluginException in project hop by apache.
the class RowsFromResultMeta method getFields.
@Override
public void getFields(IRowMeta r, String origin, IRowMeta[] info, TransformMeta nextTransform, IVariables variables, IHopMetadataProvider metadataProvider) throws HopTransformException {
for (int i = 0; i < this.fieldname.length; i++) {
IValueMeta v;
try {
v = ValueMetaFactory.createValueMeta(fieldname[i], type[i], length[i], precision[i]);
v.setOrigin(origin);
r.addValueMeta(v);
} catch (HopPluginException e) {
throw new HopTransformException(e);
}
}
}
use of org.apache.hop.core.exception.HopPluginException in project hop by apache.
the class WorkflowRunConfigurationMetadataObjectFactory method createObject.
@Override
public Object createObject(String id, Object parentObject) throws HopException {
PluginRegistry registry = PluginRegistry.getInstance();
IPlugin plugin = registry.findPluginWithId(WorkflowEnginePluginType.class, id);
if (plugin == null) {
throw new HopException("Unable to find the plugin in the context of a pipeline engine plugin for id: " + id);
}
try {
// We don't return the engine but the corresponding engine configuration
//
IWorkflowEngine engine = registry.loadClass(plugin, IWorkflowEngine.class);
IWorkflowEngineRunConfiguration engineRunConfiguration = engine.createDefaultWorkflowEngineRunConfiguration();
engineRunConfiguration.setEnginePluginId(plugin.getIds()[0]);
engineRunConfiguration.setEnginePluginName(plugin.getName());
if (parentObject != null && (parentObject instanceof IVariables)) {
engineRunConfiguration.initializeFrom((IVariables) parentObject);
}
return engineRunConfiguration;
} catch (HopPluginException e) {
throw new HopException("Unable to load the workflow engine plugin class with plugin id: " + id, e);
}
}
Aggregations