Search in sources :

Example 6 with TransConfiguration

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());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) StringWriter(java.io.StringWriter) TransMeta(org.pentaho.di.trans.TransMeta) HttpServletResponse(javax.servlet.http.HttpServletResponse) Point(org.pentaho.di.core.gui.Point) Trans(org.pentaho.di.trans.Trans) TransConfiguration(org.pentaho.di.trans.TransConfiguration) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) PrintWriter(java.io.PrintWriter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with TransConfiguration

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());
    }
}
Also used : TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) HTMLDocument(org.w3c.dom.html.HTMLDocument) Trans(org.pentaho.di.trans.Trans) TransConfiguration(org.pentaho.di.trans.TransConfiguration) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) HttpTester(org.eclipse.jetty.testing.HttpTester) Test(org.junit.Test)

Example 8 with TransConfiguration

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;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TransMeta(org.pentaho.di.trans.TransMeta) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) TransConfiguration(org.pentaho.di.trans.TransConfiguration) TransAdapter(org.pentaho.di.trans.TransAdapter) TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) Repository(org.pentaho.di.repository.Repository) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Map(java.util.Map) Trans(org.pentaho.di.trans.Trans) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 9 with TransConfiguration

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);
}
Also used : TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) TransMeta(org.pentaho.di.trans.TransMeta) TransConfiguration(org.pentaho.di.trans.TransConfiguration)

Example 10 with TransConfiguration

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);
}
Also used : TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) KettleException(org.pentaho.di.core.exception.KettleException) Trans(org.pentaho.di.trans.Trans) TransConfiguration(org.pentaho.di.trans.TransConfiguration) CarteObjectEntry(org.pentaho.di.www.CarteObjectEntry) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

TransConfiguration (org.pentaho.di.trans.TransConfiguration)15 TransExecutionConfiguration (org.pentaho.di.trans.TransExecutionConfiguration)13 Trans (org.pentaho.di.trans.Trans)12 IOException (java.io.IOException)8 KettleException (org.pentaho.di.core.exception.KettleException)8 TransMeta (org.pentaho.di.trans.TransMeta)8 PrintWriter (java.io.PrintWriter)6 ServletException (javax.servlet.ServletException)6 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)6 Repository (org.pentaho.di.repository.Repository)4 Map (java.util.Map)3 TransAdapter (org.pentaho.di.trans.TransAdapter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 Test (org.junit.Test)2 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)2 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)2