Search in sources :

Example 1 with TransAdapter

use of org.pentaho.di.trans.TransAdapter 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 (String param : params.keySet()) {
            String value = params.get(param);
            transMeta.setParameterValue(param, value);
        }
        // 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() {

                public void transFinished(Trans trans) {
                    repository.disconnect();
                }
            });
        }
        return getTransformationStatus(carteObjectId);
    } catch (KettleException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) TransMeta(org.pentaho.di.trans.TransMeta) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) TransConfiguration(org.pentaho.di.trans.TransConfiguration) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Trans(org.pentaho.di.trans.Trans) TransAdapter(org.pentaho.di.trans.TransAdapter) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 2 with TransAdapter

use of org.pentaho.di.trans.TransAdapter in project pentaho-kettle by pentaho.

the class AddTransServlet method doGet.

/**
 *    <div id="mindtouch">
 *    <h1>/kettle/addTrans</h1>
 *    <a name="POST"></a>
 *    <h2>POST</h2>
 *    <p>Uploads and executes transformation configuration XML file.
 *  Uploads xml file containing transformation and transformation_execution_configuration
 *  (wrapped in transformation_configuration tag) to be executed and executes it. Method relies
 *  on the input parameter to determine if xml or html reply should be produced. The transformation_configuration xml is
 *  transferred within request body.
 *
 *  <code>transformation name of the executed transformation </code> will be returned in the Response object
 *  or <code>message</code> describing error occurred. To determine if the call successful or not you should
 *  rely on <code>result</code> parameter in response.</p>
 *
 *    <p><b>Example Request:</b><br />
 *    <pre function="syntax.xml">
 *    POST /kettle/addTrans/?xml=Y
 *    </pre>
 *    <p>Request body should contain xml containing transformation_configuration (transformation and
 *  transformation_execution_configuration wrapped in transformation_configuration tag).</p>
 *    </p>
 *    <h3>Parameters</h3>
 *    <table class="pentaho-table">
 *    <tbody>
 *    <tr>
 *      <th>name</th>
 *      <th>description</th>
 *      <th>type</th>
 *    </tr>
 *    <tr>
 *    <td>xml</td>
 *    <td>Boolean flag set to either <code>Y</code> or <code>N</code> describing if xml or html reply
 *  should be produced.</td>
 *    <td>boolean, optional</td>
 *    </tr>
 *    </tbody>
 *    </table>
 *
 *  <h3>Response Body</h3>
 *
 *  <table class="pentaho-table">
 *    <tbody>
 *      <tr>
 *        <td align="right">element:</td>
 *        <td>(custom)</td>
 *      </tr>
 *      <tr>
 *        <td align="right">media types:</td>
 *        <td>text/xml, text/html</td>
 *      </tr>
 *    </tbody>
 *  </table>
 *    <p>Response wraps transformation name that was executed or error stack trace
 *  if an error occurred. Response has <code>result</code> OK if there were no errors. Otherwise it returns ERROR.</p>
 *
 *    <p><b>Example Response:</b></p>
 *    <pre function="syntax.xml">
 *    <?xml version="1.0" encoding="UTF-8"?>
 *    <webresult>
 *      <result>OK</result>
 *      <message>Transformation &#x27;dummy-trans&#x27; was added to Carte with id eb4a92ff-6852-4307-9f74-3c74bd61f829</message>
 *      <id>eb4a92ff-6852-4307-9f74-3c74bd61f829</id>
 *    </webresult>
 *    </pre>
 *
 *    <h3>Status Codes</h3>
 *    <table class="pentaho-table">
 *  <tbody>
 *    <tr>
 *      <th>code</th>
 *      <th>description</th>
 *    </tr>
 *    <tr>
 *      <td>200</td>
 *      <td>Request was processed and XML response is returned.</td>
 *    </tr>
 *    <tr>
 *      <td>500</td>
 *      <td>Internal server error occurs during request processing.</td>
 *    </tr>
 *  </tbody>
 *</table>
 *</div>
 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (isJettyMode() && !request.getRequestURI().startsWith(CONTEXT_PATH)) {
        return;
    }
    if (log.isDebug()) {
        logDebug("Addition of transformation requested");
    }
    boolean useXML = "Y".equalsIgnoreCase(request.getParameter("xml"));
    PrintWriter out = response.getWriter();
    BufferedReader in = request.getReader();
    if (log.isDetailed()) {
        logDetailed("Encoding: " + request.getCharacterEncoding());
    }
    if (useXML) {
        response.setContentType("text/xml");
        out.print(XMLHandler.getXMLHeader());
    } else {
        response.setContentType("text/html");
        out.println("<HTML>");
        out.println("<HEAD><TITLE>Add transformation</TITLE></HEAD>");
        out.println("<BODY>");
    }
    response.setStatus(HttpServletResponse.SC_OK);
    String realLogFilename = null;
    TransExecutionConfiguration transExecutionConfiguration = null;
    try {
        // First read the complete transformation in memory from the request
        // 
        StringBuilder xml = new StringBuilder(request.getContentLength());
        int c;
        while ((c = in.read()) != -1) {
            xml.append((char) c);
        }
        // Parse the XML, create a transformation configuration
        // 
        TransConfiguration transConfiguration = TransConfiguration.fromXML(xml.toString());
        TransMeta transMeta = transConfiguration.getTransMeta();
        transExecutionConfiguration = transConfiguration.getTransExecutionConfiguration();
        transMeta.setLogLevel(transExecutionConfiguration.getLogLevel());
        if (log.isDetailed()) {
            logDetailed("Logging level set to " + log.getLogLevel().getDescription());
        }
        transMeta.injectVariables(transExecutionConfiguration.getVariables());
        // Also copy the parameters over...
        // 
        Map<String, String> params = transExecutionConfiguration.getParams();
        for (String param : params.keySet()) {
            String value = params.get(param);
            transMeta.setParameterValue(param, value);
        }
        // If there was a repository, we know about it at this point in time.
        // 
        final Repository repository = transExecutionConfiguration.getRepository();
        String carteObjectId = UUID.randomUUID().toString();
        SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(CONTEXT_PATH, LoggingObjectType.CARTE, null);
        servletLoggingObject.setContainerObjectId(carteObjectId);
        servletLoggingObject.setLogLevel(transExecutionConfiguration.getLogLevel());
        // Create the transformation and store in the list...
        // 
        final Trans trans = new Trans(transMeta, servletLoggingObject);
        if (transExecutionConfiguration.isSetLogfile()) {
            realLogFilename = transExecutionConfiguration.getLogFileName();
            final LogChannelFileWriter logChannelFileWriter;
            try {
                FileUtil.createParentFolder(AddTransServlet.class, realLogFilename, transExecutionConfiguration.isCreateParentFolder(), trans.getLogChannel(), trans);
                logChannelFileWriter = new LogChannelFileWriter(servletLoggingObject.getLogChannelId(), KettleVFS.getFileObject(realLogFilename), transExecutionConfiguration.isSetAppendLogfile());
                logChannelFileWriter.startLogging();
                trans.addTransListener(new TransAdapter() {

                    @Override
                    public void transFinished(Trans trans) throws KettleException {
                        if (logChannelFileWriter != null) {
                            logChannelFileWriter.stopLogging();
                        }
                    }
                });
            } catch (KettleException e) {
                logError(Const.getStackTracker(e));
            }
        }
        trans.setRepository(repository);
        trans.setSocketRepository(getSocketRepository());
        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() {

                public void transFinished(Trans trans) {
                    repository.disconnect();
                }
            });
        }
        String message = "Transformation '" + trans.getName() + "' was added to Carte with id " + carteObjectId;
        if (useXML) {
            // Return the log channel id as well
            // 
            out.println(new WebResult(WebResult.STRING_OK, message, carteObjectId));
        } else {
            out.println("<H1>" + message + "</H1>");
            out.println("<p><a href=\"" + convertContextPath(GetTransStatusServlet.CONTEXT_PATH) + "?name=" + trans.getName() + "&id=" + carteObjectId + "\">Go to the transformation status page</a><p>");
        }
    } catch (Exception ex) {
        if (useXML) {
            out.println(new WebResult(WebResult.STRING_ERROR, Const.getStackTracker(ex)));
        } else {
            out.println("<p>");
            out.println("<pre>");
            ex.printStackTrace(out);
            out.println("</pre>");
        }
    }
    if (!useXML) {
        out.println("<p>");
        out.println("</BODY>");
        out.println("</HTML>");
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) LogChannelFileWriter(org.pentaho.di.core.logging.LogChannelFileWriter) 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) ServletException(javax.servlet.ServletException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) Repository(org.pentaho.di.repository.Repository) BufferedReader(java.io.BufferedReader) Trans(org.pentaho.di.trans.Trans) PrintWriter(java.io.PrintWriter)

Example 3 with TransAdapter

use of org.pentaho.di.trans.TransAdapter in project pentaho-kettle by pentaho.

the class BaseJobServlet method createTrans.

protected Trans createTrans(TransConfiguration transConfiguration) throws UnknownParamException {
    TransMeta transMeta = transConfiguration.getTransMeta();
    TransExecutionConfiguration transExecutionConfiguration = transConfiguration.getTransExecutionConfiguration();
    transMeta.setLogLevel(transExecutionConfiguration.getLogLevel());
    transMeta.injectVariables(transExecutionConfiguration.getVariables());
    // Also copy the parameters over...
    copyParameters(transMeta, transExecutionConfiguration.getParams());
    String carteObjectId = UUID.randomUUID().toString();
    SimpleLoggingObject servletLoggingObject = getServletLogging(carteObjectId, transExecutionConfiguration.getLogLevel());
    // Create the transformation and store in the list...
    final Trans trans = new Trans(transMeta, servletLoggingObject);
    trans.setMetaStore(transformationMap.getSlaveServerConfig().getMetaStore());
    if (transExecutionConfiguration.isSetLogfile()) {
        String realLogFilename = transExecutionConfiguration.getLogFileName();
        try {
            FileUtil.createParentFolder(AddTransServlet.class, realLogFilename, transExecutionConfiguration.isCreateParentFolder(), trans.getLogChannel(), trans);
            final LogChannelFileWriter logChannelFileWriter = new LogChannelFileWriter(servletLoggingObject.getLogChannelId(), KettleVFS.getFileObject(realLogFilename), transExecutionConfiguration.isSetAppendLogfile());
            logChannelFileWriter.startLogging();
            trans.addTransListener(new TransAdapter() {

                @Override
                public void transFinished(Trans trans) throws KettleException {
                    if (logChannelFileWriter != null) {
                        logChannelFileWriter.stopLogging();
                    }
                }
            });
        } catch (KettleException e) {
            logError(Const.getStackTracker(e));
        }
    }
    // If there was a repository, we know about it at this point in time.
    final Repository repository = transExecutionConfiguration.getRepository();
    trans.setRepository(repository);
    trans.setSocketRepository(getSocketRepository());
    trans.setContainerObjectId(carteObjectId);
    getTransformationMap().addTransformation(transMeta.getName(), carteObjectId, trans, transConfiguration);
    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() {

            public void transFinished(Trans trans) {
                repository.disconnect();
            }
        });
    }
    final Long passedBatchId = transExecutionConfiguration.getPassedBatchId();
    if (passedBatchId != null) {
        trans.setPassedBatchId(passedBatchId);
    }
    return trans;
}
Also used : TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) LogChannelFileWriter(org.pentaho.di.core.logging.LogChannelFileWriter) TransMeta(org.pentaho.di.trans.TransMeta) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) Trans(org.pentaho.di.trans.Trans) TransAdapter(org.pentaho.di.trans.TransAdapter)

Example 4 with TransAdapter

use of org.pentaho.di.trans.TransAdapter in project pentaho-kettle by pentaho.

the class ExecuteTransServlet method doGet.

/**
 * <div id="mindtouch">
 *    <h1>/kettle/executeTrans</h1>
 *    <a name="GET"></a>
 *    <h2>GET</h2>
 *    <p>Executes transformation from the specified repository.
 *  Connects to the repository provided as a parameter, loads the transformation from it and executes it.
 *  Empty response is returned or response contains output of an error happened during the transformation execution.
 *  Response contains <code>ERROR</code> result if error happened during transformation execution.</p>
 *
 *    <p><b>Example Request:</b><br />
 *    <pre function="syntax.xml">
 *    GET /kettle/executeTrans/?rep=my_repository&user=my_user&pass=my_password&trans=my_trans&level=INFO
 *    </pre>
 *
 *    </p>
 *    <h3>Parameters</h3>
 *    <table class="pentaho-table">
 *    <tbody>
 *    <tr>
 *      <th>name</th>
 *      <th>description</th>
 *      <th>type</th>
 *    </tr>
 *    <tr>
 *    <td>rep</td>
 *    <td>Repository id to connect to.</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>user</td>
 *    <td>User name to be used to connect to repository.</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>pass</td>
 *    <td>User password to be used to connect to repository.</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>trans</td>
 *    <td>Transfromation name to be loaded and executed.</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>level</td>
 *    <td>Logging level to be used for transformation execution (i.e. Debug).</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>*any name*</td>
 *    <td>All the other parameters will be sent to the transformation for using as variables.
 *  When necessary you can add custom parameters to the request.
 *  They will be used to set the transformation variables values..</td>
 *    <td>query</td>
 *    </tr>
 *    </tbody>
 *    </table>
 *
 *  <h3>Response Body</h3>
 *
 *  <table class="pentaho-table">
 *    <tbody>
 *      <tr>
 *        <td align="right">element:</td>
 *        <td>(custom)</td>
 *      </tr>
 *      <tr>
 *        <td align="right">media types:</td>
 *        <td>application/xml</td>
 *      </tr>
 *    </tbody>
 *  </table>
 *    <p>Response contains error output of the transformation executed or nothing
 *  if the execution was successful.</p>
 *
 *    <p><b>Example Error Response:</b></p>
 *    <pre function="syntax.xml">
 *  <webresult>
 *    <result>ERROR</result>
 *    <message>Unexpected error executing the transformation&#x3a;
 *    &#xd;&#xa;org.pentaho.di.core.exception.KettleException&#x3a;
 *    &#xd;&#xa;Unable to find transformation &#x27;dummy-trans.ktr&#x27; in directory
 *    &#x3a;&#x2f;home&#x2f;admin&#xd;&#xa;&#xd;&#xa; at
 *    org.pentaho.di.www.ExecuteTransServlet.loadTransformation&#x28;ExecuteTransServlet.java&#x3a;214&#x29;&#xd;&#xa;
 *    at org.pentaho.di.www.ExecuteTransServlet.doGet&#x28;ExecuteTransServlet.java&#x3a;104&#x29;&#xd;&#xa;
 *    at javax.servlet.http.HttpServlet.service&#x28;HttpServlet.java&#x3a;707&#x29;&#xd;&#xa;
 *    at javax.servlet.http.HttpServlet.service&#x28;HttpServlet.java&#x3a;820&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.servlet.ServletHolder.handle&#x28;ServletHolder.java&#x3a;511&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.servlet.ServletHandler.handle&#x28;ServletHandler.java&#x3a;390&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.servlet.SessionHandler.handle&#x28;SessionHandler.java&#x3a;182&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.handler.ContextHandler.handle&#x28;ContextHandler.java&#x3a;765&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.handler.ContextHandlerCollection.handle&#x28;ContextHandlerCollection.java&#x3a;230&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.handler.HandlerCollection.handle&#x28;HandlerCollection.java&#x3a;114&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.handler.HandlerWrapper.handle&#x28;HandlerWrapper.java&#x3a;152&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.Server.handle&#x28;Server.java&#x3a;326&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.HttpConnection.handleRequest&#x28;HttpConnection.java&#x3a;536&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.HttpConnection&#x24;RequestHandler.headerComplete&#x28;HttpConnection.java&#x3a;915&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.HttpParser.parseNext&#x28;HttpParser.java&#x3a;539&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.HttpParser.parseAvailable&#x28;HttpParser.java&#x3a;212&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.HttpConnection.handle&#x28;HttpConnection.java&#x3a;405&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.bio.SocketConnector&#x24;Connection.run&#x28;SocketConnector.java&#x3a;228&#x29;&#xd;&#xa;
 *    at org.mortbay.thread.QueuedThreadPool&#x24;PoolThread.run&#x28;QueuedThreadPool.java&#x3a;582&#x29;&#xd;&#xa;
 *    </message>
 *    <id/>
 *  </webresult>
 *    </pre>
 *
 *    <h3>Status Codes</h3>
 *    <table class="pentaho-table">
 *  <tbody>
 *    <tr>
 *      <th>code</th>
 *      <th>description</th>
 *    </tr>
 *    <tr>
 *      <td>200</td>
 *      <td>Request was processed.</td>
 *    </tr>
 *    <tr>
 *      <td>500</td>
 *      <td>Internal server error occurs during request processing.</td>
 *    </tr>
 *  </tbody>
 *</table>
 *</div>
 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (isJettyMode() && !request.getContextPath().startsWith(CONTEXT_PATH)) {
        return;
    }
    if (log.isDebug()) {
        logDebug(BaseMessages.getString(PKG, "ExecuteTransServlet.Log.ExecuteTransRequested"));
    }
    // Options taken from PAN
    // 
    String[] knownOptions = new String[] { "rep", "user", "pass", "trans", "level" };
    String repOption = request.getParameter("rep");
    String userOption = request.getParameter("user");
    String passOption = Encr.decryptPasswordOptionallyEncrypted(request.getParameter("pass"));
    String transOption = request.getParameter("trans");
    String levelOption = request.getParameter("level");
    response.setStatus(HttpServletResponse.SC_OK);
    String encoding = System.getProperty("KETTLE_DEFAULT_SERVLET_ENCODING", null);
    if (encoding != null && !Utils.isEmpty(encoding.trim())) {
        response.setCharacterEncoding(encoding);
        response.setContentType("text/html; charset=" + encoding);
    }
    PrintWriter out = response.getWriter();
    try {
        final Repository repository = openRepository(repOption, userOption, passOption);
        final TransMeta transMeta = loadTransformation(repository, transOption);
        // Set the servlet parameters as variables in the transformation
        // 
        String[] parameters = transMeta.listParameters();
        Enumeration<?> parameterNames = request.getParameterNames();
        while (parameterNames.hasMoreElements()) {
            String parameter = (String) parameterNames.nextElement();
            String[] values = request.getParameterValues(parameter);
            // 
            if (Const.indexOfString(parameter, knownOptions) < 0) {
                // 
                if (Const.indexOfString(parameter, parameters) < 0) {
                    transMeta.setVariable(parameter, values[0]);
                } else {
                    transMeta.setParameterValue(parameter, values[0]);
                }
            }
        }
        TransExecutionConfiguration transExecutionConfiguration = new TransExecutionConfiguration();
        LogLevel logLevel = LogLevel.getLogLevelForCode(levelOption);
        transExecutionConfiguration.setLogLevel(logLevel);
        TransConfiguration transConfiguration = new TransConfiguration(transMeta, transExecutionConfiguration);
        String carteObjectId = UUID.randomUUID().toString();
        SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(CONTEXT_PATH, LoggingObjectType.CARTE, null);
        servletLoggingObject.setContainerObjectId(carteObjectId);
        servletLoggingObject.setLogLevel(logLevel);
        // Create the transformation and store in the list...
        // 
        final Trans trans = new Trans(transMeta, servletLoggingObject);
        trans.setRepository(repository);
        trans.setSocketRepository(getSocketRepository());
        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() {

                public void transFinished(Trans trans) {
                    repository.disconnect();
                }
            });
        }
        // Pass the servlet print writer to the transformation...
        // 
        trans.setServletPrintWriter(out);
        trans.setServletReponse(response);
        trans.setServletRequest(request);
        try {
            // Execute the transformation...
            // 
            executeTrans(trans);
            out.flush();
        } catch (Exception executionException) {
            String logging = KettleLogStore.getAppender().getBuffer(trans.getLogChannelId(), false).toString();
            throw new KettleException("Error executing transformation: " + logging, executionException);
        }
    } catch (Exception ex) {
        out.println(new WebResult(WebResult.STRING_ERROR, BaseMessages.getString(PKG, "ExecuteTransServlet.Error.UnexpectedError", Const.CR + Const.getStackTracker(ex))));
    }
}
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) LogLevel(org.pentaho.di.core.logging.LogLevel) TransAdapter(org.pentaho.di.trans.TransAdapter) ServletException(javax.servlet.ServletException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) Repository(org.pentaho.di.repository.Repository) Trans(org.pentaho.di.trans.Trans) PrintWriter(java.io.PrintWriter)

Example 5 with TransAdapter

use of org.pentaho.di.trans.TransAdapter in project pentaho-kettle by pentaho.

the class TransPreviewDelegate method capturePreviewData.

public void capturePreviewData(final Trans trans, List<StepMeta> stepMetas) {
    final StringBuffer loggingText = new StringBuffer();
    // First clean out previous preview data. Otherwise this method leaks memory like crazy.
    // 
    previewLogMap.clear();
    previewMetaMap.clear();
    previewDataMap.clear();
    try {
        final TransMeta transMeta = trans.getTransMeta();
        for (final StepMeta stepMeta : stepMetas) {
            final RowMetaInterface rowMeta = transMeta.getStepFields(stepMeta).clone();
            previewMetaMap.put(stepMeta, rowMeta);
            final List<Object[]> rowsData;
            if (previewMode == PreviewMode.LAST) {
                rowsData = new LinkedList<Object[]>();
            } else {
                rowsData = new ArrayList<Object[]>();
            }
            previewDataMap.put(stepMeta, rowsData);
            previewLogMap.put(stepMeta, loggingText);
            StepInterface step = trans.findRunThread(stepMeta.getName());
            if (step != null) {
                switch(previewMode) {
                    case LAST:
                        step.addRowListener(new RowAdapter() {

                            @Override
                            public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                                try {
                                    rowsData.add(rowMeta.cloneRow(row));
                                    if (rowsData.size() > PropsUI.getInstance().getDefaultPreviewSize()) {
                                        rowsData.remove(0);
                                    }
                                } catch (Exception e) {
                                    throw new KettleStepException("Unable to clone row for metadata : " + rowMeta, e);
                                }
                            }
                        });
                        break;
                    default:
                        step.addRowListener(new RowAdapter() {

                            @Override
                            public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                                if (rowsData.size() < PropsUI.getInstance().getDefaultPreviewSize()) {
                                    try {
                                        rowsData.add(rowMeta.cloneRow(row));
                                    } catch (Exception e) {
                                        throw new KettleStepException("Unable to clone row for metadata : " + rowMeta, e);
                                    }
                                }
                            }
                        });
                        break;
                }
            }
        }
    } catch (Exception e) {
        loggingText.append(Const.getStackTracker(e));
    }
    // In case there were errors during preview...
    // 
    trans.addTransListener(new TransAdapter() {

        @Override
        public void transFinished(Trans trans) throws KettleException {
            // 
            if (trans.getErrors() != 0) {
                // 
                for (StepMetaDataCombi combi : trans.getSteps()) {
                    if (combi.copy == 0) {
                        StringBuffer logBuffer = KettleLogStore.getAppender().getBuffer(combi.step.getLogChannel().getLogChannelId(), false);
                        previewLogMap.put(combi.stepMeta, logBuffer);
                    }
                }
            }
        }
    });
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) TransAdapter(org.pentaho.di.trans.TransAdapter) StepInterface(org.pentaho.di.trans.step.StepInterface) RowAdapter(org.pentaho.di.trans.step.RowAdapter) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) Trans(org.pentaho.di.trans.Trans)

Aggregations

KettleException (org.pentaho.di.core.exception.KettleException)6 Trans (org.pentaho.di.trans.Trans)6 TransAdapter (org.pentaho.di.trans.TransAdapter)6 TransMeta (org.pentaho.di.trans.TransMeta)5 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)4 Repository (org.pentaho.di.repository.Repository)4 TransExecutionConfiguration (org.pentaho.di.trans.TransExecutionConfiguration)4 IOException (java.io.IOException)3 TransConfiguration (org.pentaho.di.trans.TransConfiguration)3 PrintWriter (java.io.PrintWriter)2 ServletException (javax.servlet.ServletException)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 LogChannelFileWriter (org.pentaho.di.core.logging.LogChannelFileWriter)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 RowAdapter (org.pentaho.di.trans.step.RowAdapter)2 BufferedReader (java.io.BufferedReader)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1