use of org.pentaho.di.trans.TransConfiguration in project pentaho-kettle by pentaho.
the class PrepareExecutionTransServletTest method testPauseTransServletEscapesHtmlWhenTransFound.
@Test
@PrepareForTest({ Encode.class })
public void testPauseTransServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
KettleLogStore.init();
HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
Trans mockTrans = mock(Trans.class);
TransConfiguration mockTransConf = mock(TransConfiguration.class);
TransMeta mockTransMeta = mock(TransMeta.class);
TransExecutionConfiguration mockTransExecutionConf = mock(TransExecutionConfiguration.class);
LogChannelInterface mockChannelInterface = mock(LogChannelInterface.class);
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter(out);
PowerMockito.spy(Encode.class);
when(mockHttpServletRequest.getContextPath()).thenReturn(PrepareExecutionTransServlet.CONTEXT_PATH);
when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
when(mockTransformationMap.getTransformation(any(CarteObjectEntry.class))).thenReturn(mockTrans);
when(mockTransformationMap.getConfiguration(any(CarteObjectEntry.class))).thenReturn(mockTransConf);
when(mockTransConf.getTransExecutionConfiguration()).thenReturn(mockTransExecutionConf);
when(mockTrans.getLogChannel()).thenReturn(mockChannelInterface);
when(mockTrans.getTransMeta()).thenReturn(mockTransMeta);
when(mockTransMeta.getMaximum()).thenReturn(new Point(10, 10));
prepareExecutionTransServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
PowerMockito.verifyStatic(atLeastOnce());
Encode.forHtml(anyString());
}
use of org.pentaho.di.trans.TransConfiguration in project pentaho-kettle by pentaho.
the class CarteIT method testAddTransServlet.
@Test
public void testAddTransServlet() {
HttpTester request = new HttpTester();
HttpTester response = new HttpTester();
request.setMethod("GET");
request.setHeader("Host", "tester");
request.setURI(RegisterTransServlet.CONTEXT_PATH + "?xml=Y");
request.setVersion("HTTP/1.0");
try {
TransExecutionConfiguration transExecConfig = new TransExecutionConfiguration();
Trans trans = CarteIT.generateTestTransformation();
TransConfiguration transConfig = new TransConfiguration(trans.getTransMeta(), transExecConfig);
request.setContent(transConfig.getXML());
response.parse(tester.getResponses(request.generate()));
Document document = XMLHandler.loadXMLString(response.getContent());
NodeList nodes = document.getElementsByTagName("result");
Assert.assertEquals(1, nodes.getLength());
Assert.assertEquals(WebResult.STRING_OK, nodes.item(0).getTextContent());
SlaveServerStatus status = getStatus();
// find the first one
SlaveServerTransStatus transStatus = status.findTransStatus(trans.getName(), null);
Assert.assertNotNull(transStatus);
Assert.assertFalse(transStatus.isPaused());
Assert.assertFalse(transStatus.isRunning());
} catch (Exception ex) {
ex.printStackTrace();
Assert.fail(ex.getMessage());
}
}
use of org.pentaho.di.trans.TransConfiguration in project pentaho-kettle by pentaho.
the class TransformationResource method addTransformation.
@PUT
@Path("/add")
@Produces({ MediaType.APPLICATION_JSON })
public TransformationStatus addTransformation(String xml) {
TransConfiguration transConfiguration;
try {
transConfiguration = TransConfiguration.fromXML(xml.toString());
TransMeta transMeta = transConfiguration.getTransMeta();
TransExecutionConfiguration transExecutionConfiguration = transConfiguration.getTransExecutionConfiguration();
transMeta.setLogLevel(transExecutionConfiguration.getLogLevel());
LogChannelInterface log = CarteSingleton.getInstance().getLog();
if (log.isDetailed()) {
log.logDetailed("Logging level set to " + log.getLogLevel().getDescription());
}
transMeta.injectVariables(transExecutionConfiguration.getVariables());
// Also copy the parameters over...
//
Map<String, String> params = transExecutionConfiguration.getParams();
for (Map.Entry<String, String> entry : params.entrySet()) {
transMeta.setParameterValue(entry.getKey(), entry.getValue());
}
// If there was a repository, we know about it at this point in time.
//
TransExecutionConfiguration executionConfiguration = transConfiguration.getTransExecutionConfiguration();
final Repository repository = transConfiguration.getTransExecutionConfiguration().getRepository();
String carteObjectId = UUID.randomUUID().toString();
SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(getClass().getName(), LoggingObjectType.CARTE, null);
servletLoggingObject.setContainerObjectId(carteObjectId);
servletLoggingObject.setLogLevel(executionConfiguration.getLogLevel());
// Create the transformation and store in the list...
//
final Trans trans = new Trans(transMeta, servletLoggingObject);
trans.setRepository(repository);
trans.setSocketRepository(CarteSingleton.getInstance().getSocketRepository());
CarteSingleton.getInstance().getTransformationMap().addTransformation(transMeta.getName(), carteObjectId, trans, transConfiguration);
trans.setContainerObjectId(carteObjectId);
if (repository != null) {
// The repository connection is open: make sure we disconnect from the repository once we
// are done with this transformation.
//
trans.addTransListener(new TransAdapter() {
@Override
public void transFinished(Trans trans) {
repository.disconnect();
}
});
}
return getTransformationStatus(carteObjectId);
} catch (KettleException e) {
e.printStackTrace();
}
return null;
}
use of org.pentaho.di.trans.TransConfiguration in project pdi-dataservice-server-plugin by pentaho.
the class TransDataServlet method monitorTransformation.
private void monitorTransformation(Trans trans) {
TransMeta transMeta = trans.getTransMeta();
TransExecutionConfiguration executionConfiguration = new TransExecutionConfiguration();
TransConfiguration config = new TransConfiguration(transMeta, executionConfiguration);
transformationMap.addTransformation(transMeta.getName(), trans.getContainerObjectId(), trans, config);
}
use of org.pentaho.di.trans.TransConfiguration in project pentaho-kettle by pentaho.
the class TransformationResource method prepareTransformation.
// change from GET to UPDATE/POST for proper REST method
@GET
@Path("/prepare/{id : .+}")
@Produces({ MediaType.APPLICATION_JSON })
public TransformationStatus prepareTransformation(@PathParam("id") String id) {
Trans trans = CarteResource.getTransformation(id);
try {
CarteObjectEntry entry = CarteResource.getCarteObjectEntry(id);
TransConfiguration transConfiguration = CarteSingleton.getInstance().getTransformationMap().getConfiguration(entry);
TransExecutionConfiguration executionConfiguration = transConfiguration.getTransExecutionConfiguration();
// Set the appropriate logging, variables, arguments, replay date, ...
// etc.
trans.setArguments(executionConfiguration.getArgumentStrings());
trans.setReplayDate(executionConfiguration.getReplayDate());
trans.setSafeModeEnabled(executionConfiguration.isSafeModeEnabled());
trans.setGatheringMetrics(executionConfiguration.isGatheringMetrics());
trans.injectVariables(executionConfiguration.getVariables());
trans.setPreviousResult(executionConfiguration.getPreviousResult());
trans.prepareExecution(null);
} catch (KettleException e) {
e.printStackTrace();
}
return getTransformationStatus(id);
}
Aggregations