Search in sources :

Example 11 with SimpleLoggingObject

use of org.pentaho.di.core.logging.SimpleLoggingObject in project pentaho-kettle by pentaho.

the class CarteSingleton method getInstance.

public static CarteSingleton getInstance() {
    try {
        if (carteSingleton == null) {
            if (slaveServerConfig == null) {
                slaveServerConfig = new SlaveServerConfig();
                SlaveServer slaveServer = new SlaveServer();
                slaveServerConfig.setSlaveServer(slaveServer);
            }
            carteSingleton = new CarteSingleton(slaveServerConfig);
            String carteObjectId = UUID.randomUUID().toString();
            SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject("CarteSingleton", LoggingObjectType.CARTE, null);
            servletLoggingObject.setContainerObjectId(carteObjectId);
            servletLoggingObject.setLogLevel(LogLevel.BASIC);
            return carteSingleton;
        } else {
            return carteSingleton;
        }
    } catch (KettleException ke) {
        throw new RuntimeException(ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SlaveServer(org.pentaho.di.cluster.SlaveServer) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject)

Example 12 with SimpleLoggingObject

use of org.pentaho.di.core.logging.SimpleLoggingObject in project pentaho-kettle by pentaho.

the class NextSequenceValueServlet method doGet.

/**
 *<div id="mindtouch">
 *    <h1>/kettle/nextSequence</h1>
 *    <a name="GET"></a>
 *    <h2>GET</h2>
 *    <p>Increments specified pre-configured sequence.
 *  Method is used for reserving a number of IDs and incrementing a sequence pre-configured in Carte server configuration
 *  by specified amount. If no increment value provided 10000 is used by default.</p>
 *
 *    <p><b>Example Request:</b><br />
 *    <pre function="syntax.xml">
 *    GET /kettle/nextSequence?name=test_seq
 *    </pre>
 *
 *    </p>
 *    <h3>Parameters</h3>
 *    <table class="pentaho-table">
 *    <tbody>
 *    <tr>
 *      <th>name</th>
 *      <th>description</th>
 *      <th>type</th>
 *    </tr>
 *    <tr>
 *    <td>name</td>
 *    <td>name of the sequence specified in Carte configuration file.</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>increment</td>
 *    <td>(optional) parameter used for incrementing sequence. If no parameter specified
 *  10000 is used by default.</td>
 *    <td>integer, optional</td>
 *    </tr>
 *    </tbody>
 *    </table>
 *
 *  <h3>Response Body</h3>
 *
 *  <table class="pentaho-table">
 *    <tbody>
 *      <tr>
 *        <td align="right">text:</td>
 *        <td>HTML</td>
 *      </tr>
 *      <tr>
 *        <td align="right">media types:</td>
 *        <td>text/xml</td>
 *      </tr>
 *    </tbody>
 *  </table>
 *    <p>Response XML containing sequence value and the increment value used.</p>
 *
 *    <p><b>Example Response:</b></p>
 *  <pre function="syntax.xml">
 *  <seq><value>570000</value><increment>10000</increment></seq>
 *  </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>404</td>
 *      <td>If the sequence was not found or error occurred during allocation</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(toString());
    }
    String name = request.getParameter(PARAM_NAME);
    long increment = Const.toLong(request.getParameter(PARAM_INCREMENT), 10000);
    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType("text/xml");
    response.setCharacterEncoding(Const.XML_ENCODING);
    PrintStream out = new PrintStream(response.getOutputStream());
    out.println(XMLHandler.getXMLHeader(Const.XML_ENCODING));
    out.println(XMLHandler.openTag(XML_TAG));
    try {
        SlaveSequence slaveSequence = getTransformationMap().getSlaveSequence(name);
        if (slaveSequence == null && getTransformationMap().isAutomaticSlaveSequenceCreationAllowed()) {
            slaveSequence = getTransformationMap().createSlaveSequence(name);
        }
        if (slaveSequence == null) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            out.println(XMLHandler.addTagValue(XML_TAG_ERROR, "Slave sequence '" + name + "' could not be found."));
        } else {
            LoggingObjectInterface loggingObject = new SimpleLoggingObject("Carte", LoggingObjectType.CARTE, null);
            long nextValue = slaveSequence.getNextValue(loggingObject, increment);
            out.println(XMLHandler.addTagValue(XML_TAG_VALUE, nextValue));
            out.println(XMLHandler.addTagValue(XML_TAG_INCREMENT, increment));
        }
    } catch (Exception e) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        out.println(XMLHandler.addTagValue(XML_TAG_ERROR, "Error retrieving next value from slave sequence: " + Const.getStackTracker(e)));
    }
    out.println(XMLHandler.closeTag(XML_TAG));
}
Also used : PrintStream(java.io.PrintStream) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 13 with SimpleLoggingObject

use of org.pentaho.di.core.logging.SimpleLoggingObject in project pentaho-kettle by pentaho.

the class BaseJobServlet method createJob.

protected Job createJob(JobConfiguration jobConfiguration) throws UnknownParamException {
    JobExecutionConfiguration jobExecutionConfiguration = jobConfiguration.getJobExecutionConfiguration();
    JobMeta jobMeta = jobConfiguration.getJobMeta();
    jobMeta.setLogLevel(jobExecutionConfiguration.getLogLevel());
    jobMeta.injectVariables(jobExecutionConfiguration.getVariables());
    // If there was a repository, we know about it at this point in time.
    final Repository repository = jobConfiguration.getJobExecutionConfiguration().getRepository();
    String carteObjectId = UUID.randomUUID().toString();
    SimpleLoggingObject servletLoggingObject = getServletLogging(carteObjectId, jobExecutionConfiguration.getLogLevel());
    // Create the transformation and store in the list...
    final Job job = new Job(repository, jobMeta, servletLoggingObject);
    // Setting variables
    job.initializeVariablesFrom(null);
    job.getJobMeta().setMetaStore(jobMap.getSlaveServerConfig().getMetaStore());
    job.getJobMeta().setInternalKettleVariables(job);
    job.injectVariables(jobConfiguration.getJobExecutionConfiguration().getVariables());
    job.setArguments(jobExecutionConfiguration.getArgumentStrings());
    job.setSocketRepository(getSocketRepository());
    copyJobParameters(job, jobExecutionConfiguration.getParams());
    // Check if there is a starting point specified.
    String startCopyName = jobExecutionConfiguration.getStartCopyName();
    if (startCopyName != null && !startCopyName.isEmpty()) {
        int startCopyNr = jobExecutionConfiguration.getStartCopyNr();
        JobEntryCopy startJobEntryCopy = jobMeta.findJobEntry(startCopyName, startCopyNr, false);
        job.setStartJobEntryCopy(startJobEntryCopy);
    }
    // Note: the plugin (Job and Trans) job entries need to call the delegation listeners in the parent job.
    if (jobExecutionConfiguration.isExpandingRemoteJob()) {
        job.addDelegationListener(new CarteDelegationHandler(getTransformationMap(), getJobMap()));
    }
    // Make sure to disconnect from the repository when the job finishes.
    if (repository != null) {
        job.addJobListener(new JobAdapter() {

            public void jobFinished(Job job) {
                repository.disconnect();
            }
        });
    }
    getJobMap().addJob(job.getJobname(), carteObjectId, job, jobConfiguration);
    final Long passedBatchId = jobExecutionConfiguration.getPassedBatchId();
    if (passedBatchId != null) {
        job.setPassedBatchId(passedBatchId);
    }
    return job;
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) Repository(org.pentaho.di.repository.Repository) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) Job(org.pentaho.di.job.Job) JobExecutionConfiguration(org.pentaho.di.job.JobExecutionConfiguration) JobAdapter(org.pentaho.di.job.JobAdapter)

Example 14 with SimpleLoggingObject

use of org.pentaho.di.core.logging.SimpleLoggingObject in project pentaho-kettle by pentaho.

the class BaseJobServlet method getServletLogging.

private SimpleLoggingObject getServletLogging(final String carteObjectId, final LogLevel level) {
    SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(getContextPath(), LoggingObjectType.CARTE, null);
    servletLoggingObject.setContainerObjectId(carteObjectId);
    servletLoggingObject.setLogLevel(level);
    return servletLoggingObject;
}
Also used : SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject)

Example 15 with SimpleLoggingObject

use of org.pentaho.di.core.logging.SimpleLoggingObject in project pentaho-kettle by pentaho.

the class ExecuteJobServlet method doGet.

/**
 * <div id="mindtouch">
 *    <h1>/kettle/executeJob</h1>
 *    <a name="GET"></a>
 *    <h2>GET</h2>
 *    <p>Executes job from the specified repository.
 *  Connects to the repository provided as a parameter, loads the job from it and executes it.
 *  Empty response is returned or response contains output of an error happened during the job execution.
 *  Response contains <code>ERROR</code> result if error happened during job execution.</p>
 *
 *    <p><b>Example Request:</b><br />
 *    <pre function="syntax.xml">
 *    GET /kettle/executeJob/?rep=my_repository&user=my_user&pass=my_password&job=my_job&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>job</td>
 *    <td>Job name to be loaded and executed.</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>level</td>
 *    <td>Logging level to be used for job execution (i.e. Debug).</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>*any name*</td>
 *    <td>All the other parameters will be sent to the job for using as variables.
 *  When necessary you can add custom parameters to the request.
 *  They will be used to set the job 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 job executed or Carte object Id
 *  if the execution was successful.</p>
 *
 *    <p><b>Example Error Response:</b></p>
 *    <pre function="syntax.xml">
 *  <webresult>
 *    <result>OK</result>
 *    <message>Job started</message>
 *    <id>74d96aa6-f29a-4bac-a26a-06a8c8f107e5</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, "ExecuteJobServlet.Log.ExecuteJobRequested"));
    }
    // Options taken from PAN
    // 
    String[] knownOptions = new String[] { "rep", "user", "pass", "job", "level" };
    String repOption = request.getParameter("rep");
    String userOption = request.getParameter("user");
    String passOption = Encr.decryptPasswordOptionallyEncrypted(request.getParameter("pass"));
    String jobOption = request.getParameter("job");
    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 JobMeta jobMeta = loadJob(repository, jobOption);
        // Set the servlet parameters as variables in the job
        // 
        String[] parameters = jobMeta.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) {
                    jobMeta.setVariable(parameter, values[0]);
                } else {
                    jobMeta.setParameterValue(parameter, values[0]);
                }
            }
        }
        JobExecutionConfiguration jobExecutionConfiguration = new JobExecutionConfiguration();
        LogLevel logLevel = LogLevel.getLogLevelForCode(levelOption);
        jobExecutionConfiguration.setLogLevel(logLevel);
        JobConfiguration jobConfiguration = new JobConfiguration(jobMeta, jobExecutionConfiguration);
        String carteObjectId = UUID.randomUUID().toString();
        SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(CONTEXT_PATH, LoggingObjectType.CARTE, null);
        servletLoggingObject.setContainerObjectId(carteObjectId);
        servletLoggingObject.setLogLevel(logLevel);
        // Create the job and store in the list...
        // 
        final Job job = new Job(repository, jobMeta, servletLoggingObject);
        job.setRepository(repository);
        job.setSocketRepository(getSocketRepository());
        getJobMap().addJob(jobMeta.getName(), carteObjectId, job, jobConfiguration);
        job.setContainerObjectId(carteObjectId);
        if (repository != null) {
            // The repository connection is open: make sure we disconnect from the repository once we
            // are done with this job.
            // 
            job.addJobListener(new JobAdapter() {

                public void jobFinished(Job job) {
                    repository.disconnect();
                }
            });
        }
        try {
            runJob(job);
            WebResult webResult = new WebResult(WebResult.STRING_OK, "Job started", carteObjectId);
            out.println(webResult.getXML());
            out.flush();
        } catch (Exception executionException) {
            String logging = KettleLogStore.getAppender().getBuffer(job.getLogChannelId(), false).toString();
            throw new KettleException("Error executing job: " + logging, executionException);
        }
    } catch (Exception ex) {
        out.println(new WebResult(WebResult.STRING_ERROR, BaseMessages.getString(PKG, "ExecuteJobServlet.Error.UnexpectedError", Const.CR + Const.getStackTracker(ex))));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) JobExecutionConfiguration(org.pentaho.di.job.JobExecutionConfiguration) JobAdapter(org.pentaho.di.job.JobAdapter) LogLevel(org.pentaho.di.core.logging.LogLevel) ServletException(javax.servlet.ServletException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) Repository(org.pentaho.di.repository.Repository) Job(org.pentaho.di.job.Job) JobConfiguration(org.pentaho.di.job.JobConfiguration) PrintWriter(java.io.PrintWriter)

Aggregations

SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)27 KettleException (org.pentaho.di.core.exception.KettleException)16 Repository (org.pentaho.di.repository.Repository)11 IOException (java.io.IOException)10 PrintWriter (java.io.PrintWriter)10 ServletException (javax.servlet.ServletException)10 Trans (org.pentaho.di.trans.Trans)10 Job (org.pentaho.di.job.Job)9 TransMeta (org.pentaho.di.trans.TransMeta)8 JobConfiguration (org.pentaho.di.job.JobConfiguration)7 JobMeta (org.pentaho.di.job.JobMeta)7 JobAdapter (org.pentaho.di.job.JobAdapter)6 JobExecutionConfiguration (org.pentaho.di.job.JobExecutionConfiguration)6 TransExecutionConfiguration (org.pentaho.di.trans.TransExecutionConfiguration)6 LoggingObjectInterface (org.pentaho.di.core.logging.LoggingObjectInterface)5 TransConfiguration (org.pentaho.di.trans.TransConfiguration)5 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)4 LogLevel (org.pentaho.di.core.logging.LogLevel)4