use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.
the class TransMetaConverterTest method testIncludesSubTransformationsFromRepository.
@Test
public void testIncludesSubTransformationsFromRepository() throws Exception {
TransMeta parentTransMeta = new TransMeta(getClass().getResource("trans-meta-converter-parent.ktr").getPath());
Repository repository = mock(Repository.class);
TransMeta transMeta = new TransMeta();
RepositoryDirectoryInterface repositoryDirectory = new RepositoryDirectory(null, "public");
String directory = getClass().getResource("").toString().replace(File.separator, "/");
when(repository.findDirectory("public")).thenReturn(repositoryDirectory);
when(repository.loadTransformation("trans-meta-converter-sub.ktr", repositoryDirectory, null, true, null)).thenReturn(transMeta);
parentTransMeta.setRepository(repository);
parentTransMeta.setRepositoryDirectory(repositoryDirectory);
parentTransMeta.setVariable("Internal.Entry.Current.Directory", "public");
Transformation transformation = TransMetaConverter.convert(parentTransMeta);
@SuppressWarnings({ "unchecked", "ConstantConditions" }) HashMap<String, Transformation> config = (HashMap<String, Transformation>) transformation.getConfig(TransMetaConverter.SUB_TRANSFORMATIONS_KEY).get();
assertEquals(1, config.size());
assertNotNull(config.get("public/trans-meta-converter-sub.ktr"));
}
use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.
the class TransWebSocketEngineAdapter method wireStatusToTransListeners.
private void wireStatusToTransListeners() throws KettleException {
messageEventService.addHandler(Util.getTransformationStatusEvent(), new MessageEventHandler() {
@Override
public void execute(Message message) throws MessageEventHandlerExecutionException {
PDIEvent<RemoteSource, Status> transStatusEvent = (PDIEvent<RemoteSource, Status>) message;
addStepPerformanceSnapShot();
getTransListeners().forEach(l -> {
try {
switch(transStatusEvent.getData()) {
case RUNNING:
l.transStarted(TransWebSocketEngineAdapter.this);
l.transActive(TransWebSocketEngineAdapter.this);
break;
case PAUSED:
break;
case STOPPED:
break;
case FAILED:
case FINISHED:
l.transFinished(TransWebSocketEngineAdapter.this);
setFinished(true);
break;
}
} catch (KettleException e) {
throw new RuntimeException(e);
}
});
}
@Override
public String getIdentifier() {
return TRANSFORMATION_STATUS;
}
});
messageEventService.addHandler(Util.getTransformationErrorEvent(), new MessageEventHandler() {
@Override
public void execute(Message message) throws MessageEventHandlerExecutionException {
Throwable throwable = ((PDIEvent<RemoteSource, LogEntry>) message).getData().getThrowable();
getLogChannel().logError("Error Executing Transformation", throwable);
errors.incrementAndGet();
finishProcess(true);
}
@Override
public String getIdentifier() {
return TRANSFORMATION_ERROR;
}
});
messageEventService.addHandler(Util.getStopMessage(), new MessageEventHandler() {
@Override
public void execute(Message message) throws MessageEventHandlerExecutionException {
StopMessage stopMessage = (StopMessage) message;
if (stopMessage.sessionWasKilled() || stopMessage.operationFailed()) {
getLogChannel().logError("Finalizing execution: " + stopMessage.getReasonPhrase());
} else {
getLogChannel().logBasic("Finalizing execution: " + stopMessage.getReasonPhrase());
}
finishProcess(false);
try {
getDaemonEndpoint().close(stopMessage.getReasonPhrase());
} catch (KettleException e) {
getLogChannel().logError("Error finalizing", e);
}
// let's shutdown the session monitor thread
closeSessionMonitor();
// Signal for the the waitUntilFinished blocker...
transFinishedSignal.countDown();
}
@Override
public String getIdentifier() {
return TRANSFORMATION_STOP;
}
});
}
use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.
the class TransWebSocketEngineAdapter method getSubSteps.
@SuppressWarnings("unchecked")
private List<StepMetaDataCombi> getSubSteps(Transformation transformation, StepMetaDataCombi combi) {
HashMap<String, Transformation> config = ((Optional<HashMap<String, Transformation>>) transformation.getConfig(TransMetaConverter.SUB_TRANSFORMATIONS_KEY)).orElse(Maps.newHashMap());
StepMetaInterface smi = combi.stepMeta.getStepMetaInterface();
return config.keySet().stream().filter(key -> stepHasDependency(combi, smi, key)).flatMap(key -> opsToSteps(config.get(key)).stream()).collect(Collectors.toList());
}
use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.
the class TransMetaConverterTest method simpleConvert.
@Test
public void simpleConvert() {
TransMeta meta = new TransMeta();
meta.setFilename("fileName");
meta.addStep(new StepMeta("stepName", stepMetaInterface));
Transformation trans = TransMetaConverter.convert(meta);
assertThat(trans.getId(), is(meta.getFilename()));
assertThat(trans.getOperations().size(), is(1));
assertThat(trans.getOperations().get(0).getId(), is("stepName"));
}
use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.
the class TransMetaConverterTest method transConfigItemsNoNameSpecified.
@Test
public void transConfigItemsNoNameSpecified() throws Exception {
TransMeta meta = new TransMeta();
Transformation trans = TransMetaConverter.convert(meta);
assertThat(trans.getConfig().get(TransMetaConverter.TRANS_META_NAME_CONF_KEY), is(TransMetaConverter.TRANS_DEFAULT_NAME));
assertThat((String) trans.getConfig().get(TransMetaConverter.TRANS_META_CONF_KEY), startsWith("<transformation>"));
}
Aggregations