Search in sources :

Example 31 with Result

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

the class Job method execute.

/**
 * Execute a job without previous results. This is a job entry point (not recursive)<br>
 * <br>
 *
 * @return the result of the execution
 *
 * @throws KettleException
 */
private Result execute() throws KettleException {
    try {
        log.snap(Metrics.METRIC_JOB_START);
        finished.set(false);
        stopped.set(false);
        KettleEnvironment.setExecutionInformation(this, rep);
        log.logMinimal(BaseMessages.getString(PKG, "Job.Comment.JobStarted"));
        ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.JobStart.id, this);
        // Start the tracking...
        JobEntryResult jerStart = new JobEntryResult(null, null, BaseMessages.getString(PKG, "Job.Comment.JobStarted"), BaseMessages.getString(PKG, "Job.Reason.Started"), null, 0, null);
        jobTracker.addJobTracker(new JobTracker(jobMeta, jerStart));
        active.set(true);
        // Where do we start?
        JobEntryCopy startpoint;
        // synchronize this to a parent job if needed.
        // 
        Object syncObject = this;
        if (parentJob != null) {
            // parallel execution in a job
            syncObject = parentJob;
        }
        synchronized (syncObject) {
            beginProcessing();
        }
        Result res = null;
        if (startJobEntryCopy == null) {
            startpoint = jobMeta.findJobEntry(JobMeta.STRING_SPECIAL_START, 0, false);
        } else {
            startpoint = startJobEntryCopy;
            res = startJobEntryResult;
        }
        if (startpoint == null) {
            throw new KettleJobException(BaseMessages.getString(PKG, "Job.Log.CounldNotFindStartingPoint"));
        }
        JobEntryResult jerEnd = null;
        if (startpoint.isStart()) {
            // Perform optional looping in the special Start job entry...
            // 
            // long iteration = 0;
            boolean isFirst = true;
            JobEntrySpecial jes = (JobEntrySpecial) startpoint.getEntry();
            while ((jes.isRepeat() || isFirst) && !isStopped()) {
                isFirst = false;
                res = execute(0, null, startpoint, null, BaseMessages.getString(PKG, "Job.Reason.Started"));
            // 
            // if (iteration > 0 && (iteration % 500) == 0) {
            // System.out.println("other 500 iterations: " + iteration);
            // }
            // iteration++;
            // 
            }
            jerEnd = new JobEntryResult(res, jes.getLogChannelId(), BaseMessages.getString(PKG, "Job.Comment.JobFinished"), BaseMessages.getString(PKG, "Job.Reason.Finished"), null, 0, null);
        } else {
            res = execute(0, res, startpoint, null, BaseMessages.getString(PKG, "Job.Reason.Started"));
            jerEnd = new JobEntryResult(res, startpoint.getEntry().getLogChannel().getLogChannelId(), BaseMessages.getString(PKG, "Job.Comment.JobFinished"), BaseMessages.getString(PKG, "Job.Reason.Finished"), null, 0, null);
        }
        // Save this result...
        jobTracker.addJobTracker(new JobTracker(jobMeta, jerEnd));
        log.logMinimal(BaseMessages.getString(PKG, "Job.Comment.JobFinished"));
        active.set(false);
        finished.set(true);
        return res;
    } finally {
        log.snap(Metrics.METRIC_JOB_STOP);
    }
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntrySpecial(org.pentaho.di.job.entries.special.JobEntrySpecial) JobTracker(org.pentaho.di.core.gui.JobTracker) FileObject(org.apache.commons.vfs2.FileObject) KettleJobException(org.pentaho.di.core.exception.KettleJobException) WebResult(org.pentaho.di.www.WebResult) Result(org.pentaho.di.core.Result)

Example 32 with Result

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

the class JobLogTable method getLogRecord.

/**
 * This method calculates all the values that are required
 *
 * @param id
 *          the id to use or -1 if no id is needed
 * @param status
 *          the log status to use
 */
public RowMetaAndData getLogRecord(LogStatus status, Object subject, Object parent) {
    if (subject == null || subject instanceof Job) {
        Job job = (Job) subject;
        Result result = null;
        if (job != null) {
            result = job.getResult();
        }
        RowMetaAndData row = new RowMetaAndData();
        for (LogTableField field : fields) {
            if (field.isEnabled()) {
                Object value = null;
                if (job != null) {
                    switch(ID.valueOf(field.getId())) {
                        case ID_JOB:
                            value = new Long(job.getBatchId());
                            break;
                        case CHANNEL_ID:
                            value = job.getLogChannelId();
                            break;
                        case JOBNAME:
                            value = job.getJobname();
                            break;
                        case STATUS:
                            value = status.getStatus();
                            break;
                        case LINES_READ:
                            value = result == null ? null : new Long(result.getNrLinesRead());
                            break;
                        case LINES_WRITTEN:
                            value = result == null ? null : new Long(result.getNrLinesWritten());
                            break;
                        case LINES_INPUT:
                            value = result == null ? null : new Long(result.getNrLinesInput());
                            break;
                        case LINES_OUTPUT:
                            value = result == null ? null : new Long(result.getNrLinesOutput());
                            break;
                        case LINES_UPDATED:
                            value = result == null ? null : new Long(result.getNrLinesUpdated());
                            break;
                        case LINES_REJECTED:
                            value = result == null ? null : new Long(result.getNrLinesRejected());
                            break;
                        case ERRORS:
                            value = result == null ? null : new Long(result.getNrErrors());
                            break;
                        case STARTDATE:
                            value = job.getStartDate();
                            break;
                        case LOGDATE:
                            value = job.getLogDate();
                            break;
                        case ENDDATE:
                            value = job.getEndDate();
                            break;
                        case DEPDATE:
                            value = job.getDepDate();
                            break;
                        case REPLAYDATE:
                            value = job.getCurrentDate();
                            break;
                        case LOG_FIELD:
                            value = getLogBuffer(job, job.getLogChannelId(), status, logSizeLimit);
                            break;
                        case EXECUTING_SERVER:
                            value = job.getExecutingServer();
                            break;
                        case EXECUTING_USER:
                            value = job.getExecutingUser();
                            break;
                        case START_JOB_ENTRY:
                            value = job.getStartJobEntryCopy() != null ? job.getStartJobEntryCopy().getName() : null;
                            break;
                        case CLIENT:
                            value = KettleClientEnvironment.getInstance().getClient() != null ? KettleClientEnvironment.getInstance().getClient().toString() : "unknown";
                            break;
                        default:
                            break;
                    }
                }
                row.addValue(field.getFieldName(), field.getDataType(), value);
                row.getRowMeta().getValueMeta(row.size() - 1).setLength(field.getLength());
            }
        }
        return row;
    } else {
        return null;
    }
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) Job(org.pentaho.di.job.Job) Result(org.pentaho.di.core.Result)

Example 33 with Result

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

the class JobEntryDTDValidator method execute.

public Result execute(Result previousResult, int nr) {
    Result result = previousResult;
    result.setResult(true);
    String realxmlfilename = getRealxmlfilename();
    String realDTDfilename = getRealDTDfilename();
    // Define a new DTD validator instance
    DTDValidator validator = new DTDValidator(log);
    // Set XML filename
    validator.setXMLFilename(realxmlfilename);
    if (dtdintern) {
        // The DTD is intern to XML file
        validator.setInternDTD(true);
    } else {
        // The DTD is extern
        // set the DTD filename
        validator.setDTDFilename(realDTDfilename);
    }
    // Validate the XML file and return the status
    boolean status = validator.validate();
    if (!status) {
        // The XML file is invalid!
        log.logError(validator.getErrorMessage());
        result.setResult(false);
        result.setNrErrors(validator.getNrErrors());
        result.setLogText(validator.getErrorMessage());
    }
    return result;
}
Also used : Result(org.pentaho.di.core.Result)

Example 34 with Result

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

the class JobEntryXMLWellFormed method execute.

public Result execute(Result previousResult, int nr) throws KettleException {
    Result result = previousResult;
    result.setNrErrors(1);
    result.setResult(false);
    List<RowMetaAndData> rows = result.getRows();
    RowMetaAndData resultRow = null;
    NrErrors = 0;
    NrWellFormed = 0;
    NrBadFormed = 0;
    limitFiles = Const.toInt(environmentSubstitute(getNrErrorsLessThan()), 10);
    successConditionBroken = false;
    successConditionBrokenExit = false;
    // Get source and destination files, also wildcard
    String[] vsourcefilefolder = source_filefolder;
    String[] vwildcard = wildcard;
    if (arg_from_previous) {
        if (log.isDetailed()) {
            logDetailed(BaseMessages.getString(PKG, "JobXMLWellFormed.Log.ArgFromPrevious.Found", (rows != null ? rows.size() : 0) + ""));
        }
    }
    if (arg_from_previous && rows != null) {
        // Copy the input row to the (command line) arguments
        for (int iteration = 0; iteration < rows.size() && !parentJob.isStopped(); iteration++) {
            if (successConditionBroken) {
                if (!successConditionBrokenExit) {
                    logError(BaseMessages.getString(PKG, "JobXMLWellFormed.Error.SuccessConditionbroken", "" + NrAllErrors));
                    successConditionBrokenExit = true;
                }
                result.setEntryNr(NrAllErrors);
                result.setNrLinesRejected(NrBadFormed);
                result.setNrLinesWritten(NrWellFormed);
                return result;
            }
            resultRow = rows.get(iteration);
            // Get source and destination file names, also wildcard
            String vsourcefilefolder_previous = resultRow.getString(0, null);
            String vwildcard_previous = resultRow.getString(1, null);
            if (log.isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "JobXMLWellFormed.Log.ProcessingRow", vsourcefilefolder_previous, vwildcard_previous));
            }
            processFileFolder(vsourcefilefolder_previous, vwildcard_previous, parentJob, result);
        }
    } else if (vsourcefilefolder != null) {
        for (int i = 0; i < vsourcefilefolder.length && !parentJob.isStopped(); i++) {
            if (successConditionBroken) {
                if (!successConditionBrokenExit) {
                    logError(BaseMessages.getString(PKG, "JobXMLWellFormed.Error.SuccessConditionbroken", "" + NrAllErrors));
                    successConditionBrokenExit = true;
                }
                result.setEntryNr(NrAllErrors);
                result.setNrLinesRejected(NrBadFormed);
                result.setNrLinesWritten(NrWellFormed);
                return result;
            }
            if (log.isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "JobXMLWellFormed.Log.ProcessingRow", vsourcefilefolder[i], vwildcard[i]));
            }
            processFileFolder(vsourcefilefolder[i], vwildcard[i], parentJob, result);
        }
    }
    // Success Condition
    result.setNrErrors(NrAllErrors);
    result.setNrLinesRejected(NrBadFormed);
    result.setNrLinesWritten(NrWellFormed);
    if (getSuccessStatus()) {
        result.setNrErrors(0);
        result.setResult(true);
    }
    displayResults();
    return result;
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) Result(org.pentaho.di.core.Result)

Example 35 with Result

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

the class JobEntryXSDValidator method execute.

public Result execute(Result previousResult, int nr) {
    Result result = previousResult;
    result.setResult(false);
    String realxmlfilename = getRealxmlfilename();
    String realxsdfilename = getRealxsdfilename();
    FileObject xmlfile = null;
    FileObject xsdfile = null;
    try {
        if (xmlfilename != null && xsdfilename != null) {
            xmlfile = KettleVFS.getFileObject(realxmlfilename, this);
            xsdfile = KettleVFS.getFileObject(realxsdfilename, this);
            if (xmlfile.exists() && xsdfile.exists()) {
                SchemaFactory factorytXSDValidator_1 = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
                // Get XSD File
                File XSDFile = new File(KettleVFS.getFilename(xsdfile));
                Schema SchematXSD = factorytXSDValidator_1.newSchema(XSDFile);
                Validator XSDValidator = SchematXSD.newValidator();
                // Get XML File
                File xmlfiletXSDValidator_1 = new File(KettleVFS.getFilename(xmlfile));
                Source sourcetXSDValidator_1 = new StreamSource(xmlfiletXSDValidator_1);
                XSDValidator.validate(sourcetXSDValidator_1);
                // Everything is OK
                result.setResult(true);
            } else {
                if (!xmlfile.exists()) {
                    logError(BaseMessages.getString(PKG, "JobEntryXSDValidator.FileDoesNotExist1.Label") + realxmlfilename + BaseMessages.getString(PKG, "JobEntryXSDValidator.FileDoesNotExist2.Label"));
                }
                if (!xsdfile.exists()) {
                    logError(BaseMessages.getString(PKG, "JobEntryXSDValidator.FileDoesNotExist1.Label") + realxsdfilename + BaseMessages.getString(PKG, "JobEntryXSDValidator.FileDoesNotExist2.Label"));
                }
                result.setResult(false);
                result.setNrErrors(1);
            }
        } else {
            logError(BaseMessages.getString(PKG, "JobEntryXSDValidator.AllFilesNotNull.Label"));
            result.setResult(false);
            result.setNrErrors(1);
        }
    } catch (SAXException ex) {
        logError("Error :" + ex.getMessage());
    } catch (Exception e) {
        logError(BaseMessages.getString(PKG, "JobEntryXSDValidator.ErrorXSDValidator.Label") + BaseMessages.getString(PKG, "JobEntryXSDValidator.ErrorXML1.Label") + realxmlfilename + BaseMessages.getString(PKG, "JobEntryXSDValidator.ErrorXML2.Label") + BaseMessages.getString(PKG, "JobEntryXSDValidator.ErrorXSD1.Label") + realxsdfilename + BaseMessages.getString(PKG, "JobEntryXSDValidator.ErrorXSD2.Label") + e.getMessage());
        result.setResult(false);
        result.setNrErrors(1);
    } finally {
        try {
            if (xmlfile != null) {
                xmlfile.close();
            }
            if (xsdfile != null) {
                xsdfile.close();
            }
        } catch (IOException e) {
        // Ignore errors
        }
    }
    return result;
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) Schema(javax.xml.validation.Schema) StreamSource(javax.xml.transform.stream.StreamSource) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) File(java.io.File) JobEntryValidatorUtils.andValidator(org.pentaho.di.job.entry.validator.JobEntryValidatorUtils.andValidator) Validator(javax.xml.validation.Validator) JobEntryValidatorUtils.fileExistsValidator(org.pentaho.di.job.entry.validator.JobEntryValidatorUtils.fileExistsValidator) JobEntryValidatorUtils.notBlankValidator(org.pentaho.di.job.entry.validator.JobEntryValidatorUtils.notBlankValidator) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) Result(org.pentaho.di.core.Result) SAXException(org.xml.sax.SAXException)

Aggregations

Result (org.pentaho.di.core.Result)192 Test (org.junit.Test)75 KettleException (org.pentaho.di.core.exception.KettleException)75 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)64 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)57 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)40 FileObject (org.apache.commons.vfs2.FileObject)34 Job (org.pentaho.di.job.Job)32 IOException (java.io.IOException)24 ResultFile (org.pentaho.di.core.ResultFile)20 File (java.io.File)17 ArrayList (java.util.ArrayList)16 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)15 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)12 Pattern (java.util.regex.Pattern)10 KettleFileException (org.pentaho.di.core.exception.KettleFileException)10 Database (org.pentaho.di.core.database.Database)9 Date (java.util.Date)8 Trans (org.pentaho.di.trans.Trans)8 Matcher (java.util.regex.Matcher)7