Search in sources :

Example 71 with Result

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

the class CopyFilesIT method testLocalFileCopy.

/**
 * Tests copying a folder contents. The folders used are created in the Java's temp location using unique folder and
 * file names.
 *
 * @throws Exception
 */
@Test
public void testLocalFileCopy() throws Exception {
    String sourceFolder = TestUtilities.createTempFolder("testLocalFileCopy_source");
    String destinationFolder = TestUtilities.createTempFolder("testLocalFileCopy_destination");
    if (Utils.isEmpty(sourceFolder) || Utils.isEmpty(destinationFolder)) {
        fail("Could not create the source and/or destination folder(s).");
    }
    // create a text file named testLocalFileCopy with a delimiter of ;
    TestUtilities.writeTextFile(sourceFolder, "testLocalFileCopy", ";");
    // the parent job
    Job parentJob = new Job();
    // Set up the job entry to do wildcard copy
    JobEntryCopyFiles jobEntry = new JobEntryCopyFiles("Job entry copy files");
    jobEntry.source_filefolder = new String[] { sourceFolder };
    jobEntry.destination_filefolder = new String[] { destinationFolder };
    jobEntry.wildcard = new String[] { "" };
    jobEntry.setParentJob(parentJob);
    // Check the result for errors.
    Result result = jobEntry.execute(createStartJobEntryResult(), 1);
    if (result.getNrErrors() != 0) {
        fail(result.getLogText());
    }
}
Also used : Job(org.pentaho.di.job.Job) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 72 with Result

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

the class JobEntryFTPPUTIT method reportsError_WhenLocalDirectoryIsNotSet.

@Test
public void reportsError_WhenLocalDirectoryIsNotSet() throws Exception {
    entry.setLocalDirectory(null);
    Result result = executeStep(entry);
    assertEquals(1, result.getNrErrors());
}
Also used : Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 73 with Result

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

the class JobEntrySFTPIT method getFile_WhenDestinationIsSetViaVariable.

@Test
public void getFile_WhenDestinationIsSetViaVariable() throws Exception {
    final String localDir = TestUtils.createTempDir();
    KettleVFS.getFileObject(localDir).createFolder();
    final String myVar = "my-var";
    final String sftpDir = "job-entry-sftp-test";
    final String fileName = "file.txt";
    uploadFile(sftpDir, fileName);
    JobEntrySFTP job = new JobEntrySFTP();
    job.setVariable(myVar, localDir);
    Job parent = mock(Job.class);
    when(parent.isStopped()).thenReturn(false);
    job.setParentJob(parent);
    job.setLogLevel(LogLevel.NOTHING);
    job.setUserName(server.getUsername());
    job.setPassword(server.getPassword());
    job.setServerName("localhost");
    job.setServerPort(Integer.toString(server.getPort()));
    job.setScpDirectory(sftpDir);
    job.setTargetDirectory(String.format("${%s}", myVar));
    job.execute(new Result(), 1);
    FileObject downloaded = KettleVFS.getFileObject(localDir + "/" + fileName);
    assertTrue(downloaded.exists());
    downloaded.delete();
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) Job(org.pentaho.di.job.Job) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 74 with Result

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

the class JobEntryDummy method execute.

@Override
public Result execute(Result prev_result, int nr) {
    Result result = new Result(nr);
    result.setResult(false);
    long filesRetrieved = 0;
    logDetailed(toString(), "Start of processing");
    // String substitution..
    String realWildcard = environmentSubstitute(wildcard);
    String realTargetDirectory = environmentSubstitute(targetDirectory);
    String realSourceDirectory = environmentSubstitute(sourceDirectory);
    DummyJob proc = new DummyJob(realSourceDirectory, realTargetDirectory, realWildcard);
    try {
        filesRetrieved = proc.process();
        result.setResult(true);
        result.setNrFilesRetrieved(filesRetrieved);
    } catch (Exception e) {
        result.setNrErrors(1);
        e.printStackTrace();
        logError(toString(), "Error processing DummyJob : " + e.getMessage());
    }
    return result;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Result(org.pentaho.di.core.Result)

Example 75 with Result

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

the class BlackBoxIT method runTrans.

public Result runTrans(String fileName, LogChannelInterface log) throws KettleException {
    // Bootstrap the Kettle API...
    // 
    KettleEnvironment.init();
    TransMeta transMeta = new TransMeta(fileName);
    Trans trans = new Trans(transMeta);
    Result result;
    try {
        trans.setLogLevel(LogLevel.ERROR);
        result = trans.getResult();
    } catch (Exception e) {
        result = trans.getResult();
        String message = "Processing has stopped because of an error: " + getPath(fileName);
        addFailure(message);
        log.logError(message, e);
        fail(message);
        return result;
    }
    try {
        trans.initializeVariablesFrom(null);
        trans.getTransMeta().setInternalKettleVariables(trans);
        trans.setSafeModeEnabled(true);
        // see if the transformation checks ok
        List<CheckResultInterface> remarks = new ArrayList<CheckResultInterface>();
        trans.getTransMeta().checkSteps(remarks, false, null, new Variables(), null, null);
        for (CheckResultInterface remark : remarks) {
            if (remark.getType() == CheckResultInterface.TYPE_RESULT_ERROR) {
                // add this to the log
                addFailure("Check error: " + getPath(fileName) + ", " + remark.getErrorCode());
                log.logError("BlackBoxTest", "Check error: " + getPath(fileName) + ", " + remark.getErrorCode());
            }
        }
        // allocate & run the required sub-threads
        try {
            trans.execute(null);
        } catch (Exception e) {
            addFailure("Unable to prepare and initialize this transformation: " + getPath(fileName));
            log.logError("BlackBoxTest", "Unable to prepare and initialize this transformation: " + getPath(fileName));
            fail("Unable to prepare and initialize this transformation: " + getPath(fileName));
            return null;
        }
        trans.waitUntilFinished();
        result = trans.getResult();
        // The result flag is not set to true by a transformation - set it to true if got no errors
        // FIXME: Find out if there is a better way to check if a transformation has thrown an error
        result.setResult(result.getNrErrors() == 0);
        return result;
    } catch (Exception e) {
        addFailure("Unexpected error occurred: " + getPath(fileName));
        log.logError("BlackBoxTest", "Unexpected error occurred: " + getPath(fileName), e);
        result.setResult(false);
        result.setNrErrors(1);
        fail("Unexpected error occurred: " + getPath(fileName));
        return result;
    }
}
Also used : Variables(org.pentaho.di.core.variables.Variables) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) Trans(org.pentaho.di.trans.Trans) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) Result(org.pentaho.di.core.Result)

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