Search in sources :

Example 1 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class KitchenCommandExecutor method execute.

public int execute(String repoName, String noRepo, String username, String trustUser, String password, String dirName, String filename, String jobName, String listJobs, String listDirs, String exportRepo, String initialDir, String listRepos, String listParams, NamedParams params, NamedParams customParams, String[] arguments) throws Throwable {
    getLog().logMinimal(BaseMessages.getString(getPkgClazz(), "Kitchen.Log.Starting"));
    Date start = Calendar.getInstance().getTime();
    logDebug("Kitchen.Log.AllocateNewJob");
    Job job = null;
    // In case we use a repository...
    Repository repository = null;
    try {
        if (getMetaStore() == null) {
            setMetaStore(createDefaultMetastore());
        }
        // Read kettle job specified on command-line?
        if (!Utils.isEmpty(repoName) || !Utils.isEmpty(filename)) {
            logDebug("Kitchen.Log.ParsingCommandLine");
            if (!Utils.isEmpty(repoName) && !YES.equalsIgnoreCase(noRepo)) {
                /**
                 * if set, _trust_user_ needs to be considered. See pur-plugin's:
                 *
                 * @link https://github.com/pentaho/pentaho-kettle/blob/8.0.0.0-R/plugins/pur/core/src/main/java/org/pentaho/di/repository/pur/PurRepositoryConnector.java#L97-L101
                 * @link https://github.com/pentaho/pentaho-kettle/blob/8.0.0.0-R/plugins/pur/core/src/main/java/org/pentaho/di/repository/pur/WebServiceManager.java#L130-L133
                 */
                if (YES.equalsIgnoreCase(trustUser)) {
                    System.setProperty("pentaho.repository.client.attemptTrust", YES);
                }
                // In case we use a repository...
                // some commands are to load a Trans from the repo; others are merely to print some repo-related information
                RepositoryMeta repositoryMeta = loadRepositoryConnection(repoName, "Kitchen.Log.LoadingRep", "Kitchen.Error.NoRepDefinied", "Kitchen.Log.FindingRep");
                repository = establishRepositoryConnection(repositoryMeta, username, password, RepositoryOperation.EXECUTE_JOB);
                job = executeRepositoryBasedCommand(repository, repositoryMeta, dirName, jobName, listJobs, listDirs);
            }
            // Try to load if from file anyway.
            if (!Utils.isEmpty(filename) && job == null) {
                // Try to load the job from file, even if it failed to load from the repository
                job = executeFilesystemBasedCommand(initialDir, filename);
            }
        } else if (YES.equalsIgnoreCase(listRepos)) {
            // list the repositories placed at repositories.xml
            printRepositories(loadRepositoryInfo("Kitchen.Log.ListRep", "Kitchen.Error.NoRepDefinied"));
        }
    } catch (KettleException e) {
        job = null;
        if (repository != null) {
            repository.disconnect();
        }
        System.out.println(BaseMessages.getString(getPkgClazz(), "Kitchen.Error.StopProcess", e.getMessage()));
    }
    if (job == null) {
        if (!YES.equalsIgnoreCase(listJobs) && !YES.equalsIgnoreCase(listDirs) && !YES.equalsIgnoreCase(listRepos)) {
            System.out.println(BaseMessages.getString(getPkgClazz(), "Kitchen.Error.canNotLoadJob"));
        }
        return CommandExecutorCodes.Kitchen.COULD_NOT_LOAD_JOB.getCode();
    }
    if (!Utils.isEmpty(exportRepo)) {
        try {
            // Export the resources linked to the currently loaded file...
            TopLevelResource topLevelResource = ResourceUtil.serializeResourceExportInterface(exportRepo, job.getJobMeta(), job, repository, getMetaStore());
            String launchFile = topLevelResource.getResourceName();
            String message = ResourceUtil.getExplanation(exportRepo, launchFile, job.getJobMeta());
            System.out.println();
            System.out.println(message);
            // Setting the list parameters option will make kitchen exit below in the parameters section
            listParams = YES;
        } catch (Exception e) {
            System.out.println(Const.getStackTracker(e));
            return CommandExecutorCodes.Kitchen.UNEXPECTED_ERROR.getCode();
        }
    }
    Result result = null;
    int returnCode = CommandExecutorCodes.Kitchen.SUCCESS.getCode();
    try {
        // Set the command line arguments on the job ...
        job.setArguments(arguments != null ? arguments : null);
        job.initializeVariablesFrom(null);
        job.setLogLevel(getLog().getLogLevel());
        job.getJobMeta().setInternalKettleVariables(job);
        job.setRepository(repository);
        job.getJobMeta().setRepository(repository);
        job.getJobMeta().setMetaStore(getMetaStore());
        // Map the command line named parameters to the actual named parameters. Skip for
        // the moment any extra command line parameter not known in the job.
        String[] jobParams = job.getJobMeta().listParameters();
        for (String param : jobParams) {
            String value = params.getParameterValue(param);
            if (value != null) {
                job.getJobMeta().setParameterValue(param, value);
            }
        }
        job.copyParametersFrom(job.getJobMeta());
        // Put the parameters over the already defined variable space. Parameters get priority.
        job.activateParameters();
        // Set custom options in the job extension map as Strings
        for (String optionName : customParams.listParameters()) {
            String optionValue = customParams.getParameterValue(optionName);
            if (optionName != null && optionValue != null) {
                job.getExtensionDataMap().put(optionName, optionValue);
            }
        }
        // List the parameters defined in this job, then simply exit...
        if (YES.equalsIgnoreCase(listParams)) {
            printJobParameters(job);
            // same as the other list options
            return CommandExecutorCodes.Kitchen.COULD_NOT_LOAD_JOB.getCode();
        }
        job.start();
        job.waitUntilFinished();
        // Execute the selected job.
        result = job.getResult();
    } finally {
        if (repository != null) {
            repository.disconnect();
        }
        if (YES.equalsIgnoreCase(trustUser)) {
            // we set it, now we sanitize it
            System.clearProperty("pentaho.repository.client.attemptTrust");
        }
    }
    getLog().logMinimal(BaseMessages.getString(getPkgClazz(), "Kitchen.Log.Finished"));
    if (result != null && result.getNrErrors() != 0) {
        getLog().logError(BaseMessages.getString(getPkgClazz(), "Kitchen.Error.FinishedWithErrors"));
        returnCode = CommandExecutorCodes.Kitchen.ERRORS_DURING_PROCESSING.getCode();
    }
    Date stop = Calendar.getInstance().getTime();
    calculateAndPrintElapsedTime(start, stop, "Kitchen.Log.StartStop", "Kitchen.Log.ProcessEndAfter", "Kitchen.Log.ProcessEndAfterLong", "Kitchen.Log.ProcessEndAfterLonger", "Kitchen.Log.ProcessEndAfterLongest");
    return returnCode;
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) TopLevelResource(org.pentaho.di.resource.TopLevelResource) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) Job(org.pentaho.di.job.Job) Date(java.util.Date) KettleException(org.pentaho.di.core.exception.KettleException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) ExecutionException(java.util.concurrent.ExecutionException) Result(org.pentaho.di.core.Result)

Example 2 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class JobEntrySetVariables method setParentJob.

@Override
public void setParentJob(Job parentJob) {
    super.setParentJob(parentJob);
    // PDI-16387 Add a listener for recovering changed values of variables
    JobEntryListener jobListener = new JobEntryListener() {

        @Override
        public void beforeExecution(Job job, JobEntryCopy jobEntryCopy, JobEntryInterface jobEntryInterface) {
            for (String key : changedInitialVariables.keySet()) {
                setVariable(key, changedInitialVariables.get(key));
                parentJob.setVariable(key, changedInitialVariables.get(key));
            }
            changedInitialVariables.clear();
        }

        @Override
        public void afterExecution(Job job, JobEntryCopy jobEntryCopy, JobEntryInterface jobEntryInterface, Result result) {
        }
    };
    parentJob.addJobEntryListener(jobListener);
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) JobEntryListener(org.pentaho.di.job.JobEntryListener) Job(org.pentaho.di.job.Job) Result(org.pentaho.di.core.Result)

Example 3 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class GetJobStatusServlet method doGet.

/**
 *   <div id="mindtouch">
 *   <h1>/kettle/jobStatus</h1>
 *   <a name="GET"></a>
 *   <h2>GET</h2>
 *   <p>Retrieves status of the specified job.
 *   Status is returned as HTML or XML output depending on the input parameters.
 *   Status contains information about last execution of the job.</p>
 *
 *   <p><b>Example Request:</b><br />
 *   <pre function="syntax.xml">
 *   GET /kettle/jobStatus/?name=dummy_job&xml=Y
 *   </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 job to be used for status generation.</td>
 *   <td>query</td>
 *   </tr>
 *   <tr>
 *   <td>xml</td>
 *   <td>Boolean flag which defines output format <code>Y</code> forces XML output to be generated.
 *   HTML is returned otherwise.</td>
 *   <td>boolean, optional</td>
 *   </tr>
 *   <tr>
 *   <td>id</td>
 *   <td>Carte id of the job to be used for status generation.</td>
 *   <td>query, optional</td>
 *   </tr>
 *   <tr>
 *   <td>from</td>
 *   <td>Start line number of the execution log to be included into response.</td>
 *   <td>integer, 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 XML or HTML response containing details about the job specified.
 *   If an error occurs during method invocation <code>result</code> field of the response
 *   will contain <code>ERROR</code> status.</p>
 *
 *   <p><b>Example Response:</b></p>
 *   <pre function="syntax.xml">
 *   <?xml version="1.0" encoding="UTF-8"?>
 *   <jobstatus>
 *   <jobname>dummy_job</jobname>
 *   <id>a4d54106-25db-41c5-b9f8-73afd42766a6</id>
 *   <status_desc>Finished</status_desc>
 *   <error_desc/>
 *   <logging_string>&#x3c;&#x21;&#x5b;CDATA&#x5b;H4sIAAAAAAAAADMyMDTRNzTUNzRXMDC3MjS2MjJQ0FVIKc3NrYzPyk8CsoNLEotKFPLTFEDc1IrU5NKSzPw8Xi4j4nRm5qUrpOaVFFUqRLuE&#x2b;vpGxhKj0y0zL7M4IzUFYieybgWNotTi0pwS2&#x2b;iSotLUWE1iTPNCdrhCGtRsXi4AOMIbLPwAAAA&#x3d;&#x5d;&#x5d;&#x3e;</logging_string>
 *   <first_log_line_nr>0</first_log_line_nr>
 *   <last_log_line_nr>20</last_log_line_nr>
 *   <result>
 *   <lines_input>0</lines_input>
 *   <lines_output>0</lines_output>
 *   <lines_read>0</lines_read>
 *   <lines_written>0</lines_written>
 *   <lines_updated>0</lines_updated>
 *   <lines_rejected>0</lines_rejected>
 *   <lines_deleted>0</lines_deleted>
 *   <nr_errors>0</nr_errors>
 *   <nr_files_retrieved>0</nr_files_retrieved>
 *   <entry_nr>0</entry_nr>
 *   <result>Y</result>
 *   <exit_status>0</exit_status>
 *   <is_stopped>N</is_stopped>
 *   <log_channel_id/>
 *   <log_text>null</log_text>
 *   <result-file></result-file>
 *   <result-rows></result-rows>
 *   </result>
 *   </jobstatus>
 *   </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>400</td>
 *   <td>Bad Request: Mandatory parameter name missing</td>
 *   </tr>
 *   <tr>
 *   <td>404</td>
 *   <td>Not found: Job not found</td>
 *   </tr>
 *   <tr>
 *   <td>409</td>
 *   <td>Conflicting: multiple jobs with the same name. must provide id</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, "GetJobStatusServlet.Log.JobStatusRequested"));
    }
    String jobName = request.getParameter("name");
    String id = request.getParameter("id");
    String root = request.getRequestURI() == null ? StatusServletUtils.PENTAHO_ROOT : request.getRequestURI().substring(0, request.getRequestURI().indexOf(CONTEXT_PATH));
    String prefix = isJettyMode() ? StatusServletUtils.STATIC_PATH : root + StatusServletUtils.RESOURCES_PATH;
    boolean useXML = "Y".equalsIgnoreCase(request.getParameter("xml"));
    int startLineNr = Const.toInt(request.getParameter("from"), 0);
    response.setStatus(HttpServletResponse.SC_OK);
    if (useXML) {
        response.setContentType(TEXT_XML);
        response.setCharacterEncoding(Const.XML_ENCODING);
    } else {
        response.setContentType("text/html;charset=UTF-8");
    }
    if (jobName == null) {
        PrintWriter out = response.getWriter();
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        String message = BaseMessages.getString(PKG, "GetJobStatusServlet.Error.JobNameIsMandatory");
        printResponse(response, useXML, out, message);
        return;
    }
    // ID is optional...
    // 
    Job job;
    CarteObjectEntry entry;
    if (Utils.isEmpty(id)) {
        if (isConflictingName(jobName)) {
            PrintWriter out = response.getWriter();
            response.setStatus(HttpServletResponse.SC_CONFLICT);
            String message = BaseMessages.getString(PKG, "GetJobStatusServlet.Error.ConflictingJobName");
            printResponse(response, useXML, out, message);
            return;
        }
        // get the first job that matches...
        entry = getJobMap().getFirstCarteObjectEntry(jobName);
        if (entry == null) {
            job = null;
        } else {
            id = entry.getId();
            job = getJobMap().getJob(entry);
        }
    } else {
        // 
        if (Utils.isEmpty(jobName)) {
            // Take the ID into account!
            // 
            job = getJobMap().findJob(id);
        } else {
            entry = new CarteObjectEntry(jobName, id);
            job = getJobMap().getJob(entry);
            if (job != null) {
                jobName = job.getJobname();
            }
        }
    }
    if (job != null) {
        if (useXML) {
            try {
                OutputStream out = null;
                byte[] data = null;
                String logId = job.getLogChannelId();
                boolean finishedOrStopped = job.isFinished() || job.isStopped();
                if (finishedOrStopped && (data = cache.get(logId, startLineNr)) != null) {
                    response.setContentLength(XML_HEADER.length + data.length);
                    out = response.getOutputStream();
                    out.write(XML_HEADER);
                    out.write(data);
                    out.flush();
                } else {
                    int lastLineNr = KettleLogStore.getLastBufferLineNr();
                    String logText = getLogText(job, startLineNr, lastLineNr);
                    response.setContentType(TEXT_XML);
                    response.setCharacterEncoding(Const.XML_ENCODING);
                    SlaveServerJobStatus jobStatus = new SlaveServerJobStatus(jobName, id, job.getStatus());
                    jobStatus.setFirstLoggingLineNr(startLineNr);
                    jobStatus.setLastLoggingLineNr(lastLineNr);
                    jobStatus.setLogDate(job.getLogDate());
                    // The log can be quite large at times, we are going to putIfAbsent a base64 encoding around a compressed
                    // stream
                    // of bytes to handle this one.
                    String loggingString = HttpUtil.encodeBase64ZippedString(logText);
                    jobStatus.setLoggingString(loggingString);
                    // Also set the result object...
                    // 
                    // might be null
                    jobStatus.setResult(job.getResult());
                    String xml = jobStatus.getXML();
                    data = xml.getBytes(Charset.forName(Const.XML_ENCODING));
                    out = response.getOutputStream();
                    response.setContentLength(XML_HEADER.length + data.length);
                    out.write(XML_HEADER);
                    out.write(data);
                    out.flush();
                    if (finishedOrStopped && (jobStatus.isFinished() || jobStatus.isStopped()) && logId != null) {
                        cache.put(logId, xml, startLineNr);
                    }
                }
                response.flushBuffer();
            } catch (KettleException e) {
                response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                throw new ServletException(BaseMessages.getString(PKG, "GetJobStatusServlet.Error.UnableToGetJobStatusInXML"), e);
            }
        } else {
            PrintWriter out = response.getWriter();
            int lastLineNr = KettleLogStore.getLastBufferLineNr();
            int tableBorder = 0;
            response.setContentType("text/html");
            out.println("<HTML>");
            out.println("<HEAD>");
            out.println("<TITLE>" + BaseMessages.getString(PKG, "GetJobStatusServlet.KettleJobStatus") + "</TITLE>");
            if (EnvUtil.getSystemProperty(Const.KETTLE_CARTE_REFRESH_STATUS, "N").equalsIgnoreCase("Y")) {
                out.println("<META http-equiv=\"Refresh\" content=\"10;url=" + convertContextPath(GetJobStatusServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(Const.NVL(jobName, ""), "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\">");
            }
            out.println("<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
            if (isJettyMode()) {
                out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/css/carte.css\" />");
            } else {
                out.print(StatusServletUtils.getPentahoStyles(root));
            }
            out.println("</HEAD>");
            out.println("<BODY style=\"overflow: auto;\">");
            out.println("<div class=\"row\" id=\"pucHeader\">");
            out.println("<div class=\"workspaceHeading\" style=\"padding: 0px 0px 0px 10px;\">" + Encode.forHtml(BaseMessages.getString(PKG, "GetJobStatusServlet.JobStatus", jobName)) + "</div>");
            out.println("</div>");
            try {
                out.println("<div class=\"row\" style=\"padding: 0px 0px 0px 30px\">");
                out.println("<div class=\"row\" style=\"padding-top: 30px;\">");
                out.print(HREF + convertContextPath(GetStatusServlet.CONTEXT_PATH) + "\">");
                out.print("<img src=\"" + prefix + "/images/back.svg\" style=\"margin-right: 5px; width: 16px; height: 16px; vertical-align: middle;\">");
                out.print(BaseMessages.getString(PKG, "CarteStatusServlet.BackToCarteStatus") + "</a>");
                out.println("</div>");
                out.println("<div class=\"row\" style=\"padding: 30px 0px 75px 0px; display: table;\">");
                out.println("<div style=\"display: table-row;\">");
                out.println("<div style=\"padding: 0px 30px 0px 0px; width: 60px; display: table-cell; vertical-align: top;\">");
                out.println("<img src=\"" + prefix + "/images/job.svg\" style=\"width: 60px; height: 60px;\"></img>");
                out.println("</div>");
                out.println("<div style=\"vertical-align: top; display: table-cell;\">");
                out.println("<table style=\"border-collapse: collapse;\" border=\"" + tableBorder + "\">");
                out.print("<tr class=\"cellTableRow\" style=\"border: solid; border-width: 1px 0; border-top: none; border-color: #E3E3E3; font-size: 12; text-align: left;\"> <th style=\"font-weight: normal; padding: 8px 10px 10px 10px\" class=\"cellTableHeader\">" + BaseMessages.getString(PKG, "TransStatusServlet.CarteObjectId") + "</th> <th style=\"font-weight: normal; padding: 8px 10px 10px 10px\" class=\"cellTableHeader\">" + BaseMessages.getString(PKG, "TransStatusServlet.TransStatus") + "</th> <th style=\"font-weight: normal; padding: 8px 10px 10px 10px\" class=\"cellTableHeader\">" + BaseMessages.getString(PKG, "TransStatusServlet.LastLogDate") + "</th> </tr>");
                out.print("<tr class=\"cellTableRow\" style=\"border: solid; border-width: 1px 0; border-bottom: none; font-size: 12; text-align:left\">");
                out.print("<td style=\"padding: 8px 10px 10px 10px\" class=\"cellTableCell cellTableFirstColumn\">" + Const.NVL(Encode.forHtml(id), "") + "</td>");
                out.print("<td style=\"padding: 8px 10px 10px 10px\" class=\"cellTableCell\" id=\"statusColor\" style=\"font-weight: bold;\">" + job.getStatus() + "</td>");
                String dateStr = XMLHandler.date2string(job.getLogDate());
                dateStr = dateStr == null ? "-" : dateStr.substring(0, dateStr.indexOf(' '));
                out.print("<td style=\"padding: 8px 10px 10px 10px\" class=\"cellTableCell cellTableLastColumn\">" + dateStr + "</td>");
                out.print("</tr>");
                out.print("</table>");
                out.print("</div>");
                out.println("<div style=\"padding: 0px 0px 0px 20px; width: 90px; display: table-cell; vertical-align: top;\">");
                out.print("<div style=\"display: block; margin-left: auto; margin-right: auto; padding: 5px 0px;\">");
                out.print("<a target=\"_blank\" href=\"" + convertContextPath(GetJobStatusServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(jobName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "&xml=y\">" + "<img src=\"" + prefix + "/images/view-as-xml.svg\" style=\"display: block; margin: auto; width: 22px; height: 22px;\"></a>");
                out.print("</div>");
                out.println("<div style=\"text-align: center; padding-top: 12px; font-size: 12px;\">");
                out.print("<a target=\"_blank\" href=\"" + convertContextPath(GetJobStatusServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(jobName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "&xml=y\">" + BaseMessages.getString(PKG, "TransStatusServlet.ShowAsXml") + "</a>");
                out.print("</div>");
                out.print("</div>");
                out.print("</div>");
                out.print("</div>");
                out.print("<div class=\"row\" style=\"padding: 0px 0px 75px 0px;\">");
                out.print("<div class=\"workspaceHeading\">Canvas preview</div>");
                // Show job image?
                // 
                Point max = job.getJobMeta().getMaximum();
                // max.x += 20;
                max.y += 20;
                out.print("<iframe height=\"" + max.y + "\" width=\"" + 875 + "\" seamless src=\"" + convertContextPath(GetJobImageServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(jobName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\"></iframe>");
                out.print("</div>");
                // Put the logging below that.
                out.print("<div class=\"row\" style=\"padding: 0px 0px 30px 0px;\">");
                out.print("<div class=\"workspaceHeading\">Job log</div>");
                out.println("<textarea id=\"joblog\" cols=\"120\" rows=\"20\" wrap=\"off\" " + "name=\"Job log\" readonly=\"readonly\" style=\"height: auto;\">" + Encode.forHtml(getLogText(job, startLineNr, lastLineNr)) + "</textarea>");
                out.print("</div>");
                out.println("<script type=\"text/javascript\">");
                out.println("element = document.getElementById( 'statusColor' );");
                out.println("if( element.innerHTML == 'Running' || element.innerHTML == 'Finished' ){");
                out.println("element.style.color = '#009900';");
                out.println("} else if( element.innerHTML == 'Stopped' ) {");
                out.println("element.style.color = '#7C0B2B';");
                out.println("} else {");
                out.println("element.style.color = '#F1C40F';");
                out.println("}");
                out.println("</script>");
                out.println("<script type=\"text/javascript\"> ");
                out.println("  joblog.scrollTop=joblog.scrollHeight; ");
                out.println("</script> ");
            } catch (Exception ex) {
                response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                out.println("<pre>");
                out.println(Encode.forHtml(Const.getStackTracker(ex)));
                out.println("</pre>");
            }
            out.println("</div>");
            out.println("</BODY>");
            out.println("</HTML>");
        }
    } else {
        PrintWriter out = response.getWriter();
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        String message = BaseMessages.getString(PKG, "StartJobServlet.Log.SpecifiedJobNotFound", jobName, id);
        if (useXML) {
            out.println(new WebResult(WebResult.STRING_ERROR, message));
        } else {
            out.println("<H1>" + Encode.forHtml(message) + "</H1>");
            out.println(HREF + convertContextPath(GetStatusServlet.CONTEXT_PATH) + "\">" + BaseMessages.getString(PKG, "JobStatusServlet.BackToStatusPage") + "</a><p>");
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) OutputStream(java.io.OutputStream) Point(org.pentaho.di.core.gui.Point) Point(org.pentaho.di.core.gui.Point) DuplicateKeyException(org.pentaho.di.www.exception.DuplicateKeyException) ServletException(javax.servlet.ServletException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) Job(org.pentaho.di.job.Job) PrintWriter(java.io.PrintWriter)

Example 4 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class RegisterJobServlet method generateBody.

@Override
WebResult generateBody(HttpServletRequest request, HttpServletResponse response, boolean useXML) throws IOException, KettleException {
    final String xml = IOUtils.toString(request.getInputStream());
    // Parse the XML, create a job configuration
    JobConfiguration jobConfiguration = JobConfiguration.fromXML(xml);
    Job job = createJob(jobConfiguration);
    String message = "Job '" + job.getJobname() + "' was added to the list with id " + job.getContainerObjectId();
    return new WebResult(WebResult.STRING_OK, message, job.getContainerObjectId());
}
Also used : Job(org.pentaho.di.job.Job) JobConfiguration(org.pentaho.di.job.JobConfiguration)

Example 5 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class RegisterPackageServlet method generateBody.

@Override
WebResult generateBody(HttpServletRequest request, HttpServletResponse response, boolean useXML) throws KettleException {
    String archiveUrl = copyRequestToDirectory(request, createTempDirString());
    // the resource to load
    String load = request.getParameter(PARAMETER_LOAD);
    String zipBaseUrl = extract(archiveUrl);
    if (!Utils.isEmpty(load)) {
        String fileUrl = getStartFileUrl(zipBaseUrl, load);
        String resultId;
        if (isJob(request)) {
            Node node = getConfigNode(zipBaseUrl, Job.CONFIGURATION_IN_EXPORT_FILENAME, JobExecutionConfiguration.XML_TAG);
            JobExecutionConfiguration jobExecutionConfiguration = new JobExecutionConfiguration(node);
            JobMeta jobMeta = new JobMeta(fileUrl, jobExecutionConfiguration.getRepository());
            JobConfiguration jobConfiguration = new JobConfiguration(jobMeta, jobExecutionConfiguration);
            Job job = createJob(jobConfiguration);
            resultId = job.getContainerObjectId();
        } else {
            Node node = getConfigNode(zipBaseUrl, Trans.CONFIGURATION_IN_EXPORT_FILENAME, TransExecutionConfiguration.XML_TAG);
            TransExecutionConfiguration transExecutionConfiguration = new TransExecutionConfiguration(node);
            TransMeta transMeta = new TransMeta(fileUrl, transExecutionConfiguration.getRepository());
            TransConfiguration transConfiguration = new TransConfiguration(transMeta, transExecutionConfiguration);
            Trans trans = createTrans(transConfiguration);
            resultId = trans.getContainerObjectId();
        }
        // zip file no longer needed, contents were extracted
        deleteArchive(archiveUrl);
        return new WebResult(WebResult.STRING_OK, fileUrl, resultId);
    }
    return null;
}
Also used : TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) JobMeta(org.pentaho.di.job.JobMeta) Node(org.w3c.dom.Node) TransMeta(org.pentaho.di.trans.TransMeta) Job(org.pentaho.di.job.Job) JobExecutionConfiguration(org.pentaho.di.job.JobExecutionConfiguration) TransConfiguration(org.pentaho.di.trans.TransConfiguration) Trans(org.pentaho.di.trans.Trans) JobConfiguration(org.pentaho.di.job.JobConfiguration)

Aggregations

Job (org.pentaho.di.job.Job)122 Test (org.junit.Test)52 JobMeta (org.pentaho.di.job.JobMeta)50 Result (org.pentaho.di.core.Result)25 PrintWriter (java.io.PrintWriter)22 KettleException (org.pentaho.di.core.exception.KettleException)20 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)20 Trans (org.pentaho.di.trans.Trans)20 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)18 StringWriter (java.io.StringWriter)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 HttpServletResponse (javax.servlet.http.HttpServletResponse)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 Before (org.junit.Before)11 Point (org.pentaho.di.core.gui.Point)11 Repository (org.pentaho.di.repository.Repository)11 ArrayList (java.util.ArrayList)10 JobExecutionConfiguration (org.pentaho.di.job.JobExecutionConfiguration)10 TransMeta (org.pentaho.di.trans.TransMeta)10 File (java.io.File)9