Search in sources :

Example 16 with CheckResultInterface

use of org.pentaho.di.core.CheckResultInterface 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)

Example 17 with CheckResultInterface

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

the class BaseStreamStep method init.

public boolean init(StepMetaInterface stepMetaInterface, StepDataInterface stepDataInterface) {
    Preconditions.checkNotNull(stepMetaInterface);
    stepMeta = (BaseStreamStepMeta) stepMetaInterface;
    stepMeta.setParentStepMeta(getStepMeta());
    stepMeta.setFileName(stepMeta.getTransformationPath());
    boolean superInit = super.init(stepMetaInterface, stepDataInterface);
    try {
        TransMeta transMeta = TransExecutorMeta.loadMappingMeta(stepMeta, getTransMeta().getRepository(), getTransMeta().getMetaStore(), getParentVariableSpace());
        subtransExecutor = new SubtransExecutor(getStepname(), getTrans(), transMeta, true, new TransExecutorParameters(), environmentSubstitute(stepMeta.getSubStep()));
    } catch (KettleException e) {
        log.logError(e.getLocalizedMessage(), e);
        return false;
    }
    List<CheckResultInterface> remarks = new ArrayList<>();
    stepMeta.check(remarks, getTransMeta(), stepMeta.getParentStepMeta(), // these parameters are not used inside the method
    null, // these parameters are not used inside the method
    null, // these parameters are not used inside the method
    null, // these parameters are not used inside the method
    null, variables, getRepository(), getMetaStore());
    boolean errorsPresent = remarks.stream().filter(result -> result.getType() == CheckResultInterface.TYPE_RESULT_ERROR).peek(result -> logError(result.getText())).count() > 0;
    if (errorsPresent) {
        return false;
    }
    return superInit;
}
Also used : Result(org.pentaho.di.core.Result) Trans(org.pentaho.di.trans.Trans) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) StreamWindow(org.pentaho.di.trans.streaming.api.StreamWindow) KettleException(org.pentaho.di.core.exception.KettleException) TransExecutorMeta(org.pentaho.di.trans.steps.transexecutor.TransExecutorMeta) ArrayList(java.util.ArrayList) TransMeta(org.pentaho.di.trans.TransMeta) StepStatus(org.pentaho.di.trans.step.StepStatus) BaseMessages(org.pentaho.di.i18n.BaseMessages) StepMeta(org.pentaho.di.trans.step.StepMeta) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Collection(java.util.Collection) Throwables(com.google.common.base.Throwables) StreamSource(org.pentaho.di.trans.streaming.api.StreamSource) BaseStep(org.pentaho.di.trans.step.BaseStep) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) List(java.util.List) SubtransExecutor(org.pentaho.di.trans.SubtransExecutor) KettleStepException(org.pentaho.di.core.exception.KettleStepException) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TransExecutorParameters(org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters) Collections(java.util.Collections) KettleException(org.pentaho.di.core.exception.KettleException) SubtransExecutor(org.pentaho.di.trans.SubtransExecutor) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) TransExecutorParameters(org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters) CheckResultInterface(org.pentaho.di.core.CheckResultInterface)

Example 18 with CheckResultInterface

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

the class RowGenerator method init.

@Override
public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
    try {
        meta = (RowGeneratorMeta) smi;
        data = (RowGeneratorData) sdi;
        if (super.init(smi, sdi)) {
            // Determine the number of rows to generate...
            data.rowLimit = Const.toLong(environmentSubstitute(meta.getRowLimit()), -1L);
            data.rowsWritten = 0L;
            data.delay = Const.toLong(environmentSubstitute(meta.getIntervalInMs()), -1L);
            if (data.rowLimit < 0L) {
                // Unable to parse
                logError(BaseMessages.getString(PKG, "RowGenerator.Wrong.RowLimit.Number"));
                // fail
                return false;
            }
            // Create a row (constants) with all the values in it...
            // stores the errors...
            List<CheckResultInterface> remarks = new ArrayList<CheckResultInterface>();
            RowMetaAndData outputRow = buildRow(meta, remarks, getStepname());
            if (!remarks.isEmpty()) {
                for (int i = 0; i < remarks.size(); i++) {
                    CheckResult cr = (CheckResult) remarks.get(i);
                    logError(cr.getText());
                }
                return false;
            }
            data.outputRowData = outputRow.getData();
            data.outputRowMeta = outputRow.getRowMeta();
            return true;
        }
        return false;
    } catch (Exception e) {
        setErrors(1L);
        logError("Error initializing step", e);
        return false;
    }
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) CheckResult(org.pentaho.di.core.CheckResult) ArrayList(java.util.ArrayList) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) KettleException(org.pentaho.di.core.exception.KettleException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Example 19 with CheckResultInterface

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

the class RowGeneratorMeta method getFields.

public void getFields(RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    try {
        List<CheckResultInterface> remarks = new ArrayList<CheckResultInterface>();
        RowMetaAndData rowMetaAndData = RowGenerator.buildRow(this, remarks, origin);
        if (!remarks.isEmpty()) {
            StringBuilder stringRemarks = new StringBuilder();
            for (CheckResultInterface remark : remarks) {
                stringRemarks.append(remark.toString()).append(Const.CR);
            }
            throw new KettleStepException(stringRemarks.toString());
        }
        for (ValueMetaInterface valueMeta : rowMetaAndData.getRowMeta().getValueMetaList()) {
            valueMeta.setOrigin(origin);
        }
        row.mergeRowMeta(rowMetaAndData.getRowMeta());
    } catch (Exception e) {
        throw new KettleStepException(e);
    }
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ArrayList(java.util.ArrayList) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 20 with CheckResultInterface

use of org.pentaho.di.core.CheckResultInterface in project pdi-dataservice-server-plugin by pentaho.

the class MongoDbBasicValidation method checkStep.

@Override
public void checkStep(CheckStepsExtension checkStepExtension, DataServiceMeta dataServiceMeta, LogChannelInterface log) {
    StepMeta stepMeta = checkStepExtension.getStepMetas()[0];
    List<CheckResultInterface> remarks = checkStepExtension.getRemarks();
    MongoDbInputMeta mongoDbMeta = (MongoDbInputMeta) checkStepExtension.getStepMetas()[0].getStepMetaInterface();
    VariableSpace space = checkStepExtension.getVariableSpace();
    checkOutputJson(stepMeta, remarks, mongoDbMeta);
    checkPushdownParameter(stepMeta, remarks, mongoDbMeta, space);
    checkParameterGenerationOptimizedMeta(checkStepExtension, dataServiceMeta, log);
}
Also used : VariableSpace(org.pentaho.di.core.variables.VariableSpace) MongoDbInputMeta(org.pentaho.di.trans.steps.mongodbinput.MongoDbInputMeta) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) StepMeta(org.pentaho.di.trans.step.StepMeta)

Aggregations

CheckResultInterface (org.pentaho.di.core.CheckResultInterface)37 ArrayList (java.util.ArrayList)33 Test (org.junit.Test)23 Variables (org.pentaho.di.core.variables.Variables)20 TransMeta (org.pentaho.di.trans.TransMeta)8 StepMeta (org.pentaho.di.trans.step.StepMeta)8 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)7 Repository (org.pentaho.di.repository.Repository)6 IMetaStore (org.pentaho.metastore.api.IMetaStore)6 SalesforceMetaTest (org.pentaho.di.trans.steps.salesforce.SalesforceMetaTest)5 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)4 KettleException (org.pentaho.di.core.exception.KettleException)4 VariableSpace (org.pentaho.di.core.variables.VariableSpace)3 Result (org.pentaho.di.core.Result)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 Trans (org.pentaho.di.trans.Trans)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Throwables (com.google.common.base.Throwables)1