Search in sources :

Example 46 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ConnectionUtils method checkConnection.

/**
 * check whether the connection is available.
 *
 * @param datamanager
 * @param analysisName
 * @return boolean
 */
public static boolean checkConnection(DataManager datamanager, String analysisName) {
    Connection analysisDataProvider = ConnectionUtils.getConnectionFromDatamanager(datamanager);
    ReturnCode connectionAvailable = isConnectionAvailable(analysisDataProvider);
    if (!connectionAvailable.isOk()) {
        log.error(connectionAvailable.getMessage());
        MessageDialogWithToggle.openError(Display.getCurrent().getActiveShell(), // $NON-NLS-1$
        Messages.getString("ConnectionUtils.checkConnFailTitle"), // $NON-NLS-1$
        Messages.getString("ConnectionUtils.checkConnFailMsg", analysisName));
        return false;
    }
    return true;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) ManagerConnection(org.talend.metadata.managment.repository.ManagerConnection)

Example 47 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ConnectionUtils method isConnectionAvailable.

/**
 * This method is used to check conectiton is avalible for analysis or report ,when analysis or report runs.
 *
 * @param analysisDataProvider
 * @return
 */
public static ReturnCode isConnectionAvailable(Connection analysisDataProvider) {
    ReturnCode returnCode = new ReturnCode();
    if (analysisDataProvider == null) {
        returnCode.setOk(false);
        // $NON-NLS-1$
        returnCode.setMessage(Messages.getString("ConnectionUtils.checkConnFailTitle"));
        return returnCode;
    }
    // check hive connection
    IMetadataConnection metadataConnection = ConvertionHelper.convert(analysisDataProvider);
    if (metadataConnection != null) {
        if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
            try {
                // need to do this first when check for hive embed connection.
                if (isHiveEmbedded(analysisDataProvider)) {
                    JavaSqlFactory.doHivePreSetup(analysisDataProvider);
                }
                HiveConnectionManager.getInstance().checkConnection(metadataConnection);
                returnCode.setOk(true);
            } catch (ClassNotFoundException e) {
                returnCode.setOk(false);
                returnCode.setMessage(e.toString());
            } catch (InstantiationException e) {
                returnCode.setOk(false);
                returnCode.setMessage(e.toString());
            } catch (IllegalAccessException e) {
                returnCode.setOk(false);
                returnCode.setMessage(e.toString());
            } catch (SQLException e) {
                returnCode.setOk(false);
                returnCode.setMessage(e.toString());
            }
            return returnCode;
        }
    }
    // MOD klliu check file connection is available
    if (analysisDataProvider instanceof FileConnection) {
        FileConnection fileConn = (FileConnection) analysisDataProvider;
        // ADD msjian TDQ-4559 2012-2-28: when the fileconnection is context mode, getOriginalFileConnection.
        if (fileConn.isContextMode()) {
            IRepositoryContextService service = CoreRuntimePlugin.getInstance().getRepositoryContextService();
            if (service != null) {
                fileConn = service.cloneOriginalValueConnection(fileConn);
            }
        }
        // TDQ-4559 ~
        String filePath = fileConn.getFilePath();
        try {
            BufferedReader filePathAvailable = FilesUtils.isFilePathAvailable(filePath, fileConn);
            if (filePathAvailable == null) {
                returnCode.setOk(false);
                // $NON-NLS-1$ //$NON-NLS-2$
                returnCode.setMessage(Messages.getString("ConnectionUtils.checkConnFailTitle") + " " + filePath);
            }
        } catch (UnsupportedEncodingException e) {
            returnCode.setOk(false);
            returnCode.setMessage(e.toString());
        } catch (FileNotFoundException e) {
            returnCode.setOk(false);
            returnCode.setMessage(e.toString());
        } catch (IOException e) {
            returnCode.setOk(false);
            returnCode.setMessage(e.toString());
        }
        return returnCode;
    }
    // ~
    Properties props = new Properties();
    props.put(TaggedValueHelper.USER, JavaSqlFactory.getUsername(analysisDataProvider));
    props.put(TaggedValueHelper.PASSWORD, JavaSqlFactory.getPassword(analysisDataProvider));
    if (analysisDataProvider instanceof DatabaseConnection) {
        // MOD qiongli TDQ-11507,for GeneralJdbc,should check connection too after validation jar and jdbc driver .
        if (isTcompJdbc(analysisDataProvider) || isGeneralJdbc(analysisDataProvider)) {
            ReturnCode rcJdbc = checkJdbcJarFilePathDriverClassName((DatabaseConnection) analysisDataProvider);
            if (!rcJdbc.isOk()) {
                return rcJdbc;
            }
        }
        // MOD qiongli 2014-5-14 in order to check and connect a dbConnection by a correct driver,replace
        // 'ConnectionUtils.checkConnection(...)' with 'managerConn.check(metadataConnection)'.
        ManagerConnection managerConn = new ManagerConnection();
        returnCode.setOk(managerConn.check(metadataConnection));
        returnCode.setMessage(managerConn.getMessageException());
    }
    return returnCode;
}
Also used : ManagerConnection(org.talend.metadata.managment.repository.ManagerConnection) ReturnCode(org.talend.utils.sugars.ReturnCode) SQLException(java.sql.SQLException) FileNotFoundException(java.io.FileNotFoundException) IRepositoryContextService(org.talend.core.IRepositoryContextService) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) IOException(java.io.IOException) Properties(java.util.Properties) BufferedReader(java.io.BufferedReader) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection)

Example 48 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ReportExecutor method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.analysis.IReportExecutor#execute(org.talend.dataquality.reports.TdReport)
     */
public ReturnCode execute(TdReport report, IProgressMonitor monitor) throws AnalysisExecutionException {
    atLeastOneFailure = false;
    long startTime = System.currentTimeMillis();
    if (report.eIsProxy()) {
        report = (TdReport) EObjectHelper.resolveObject(report);
    }
    EList<AnalysisMap> analysisMaps = report.getAnalysisMap();
    StringBuilder strBuilder = new StringBuilder();
    // loop on analysis maps is faster than loop on analyses
    for (AnalysisMap analysisMap : analysisMaps) {
        Analysis analysis = analysisMap.getAnalysis();
        if (analysisMap.isMustRefresh()) {
            if (analysis == null) {
                return new ReturnCode(Messages.getString("ReportExecutor.CannotEvaluateNullAnalysis", report.getName()), // $NON-NLS-1$
                false);
            }
            ReturnCode executeRc = AnalysisExecutorSelector.executeAnalysis(analysis, monitor);
            if (executeRc.getMessage() != null && !StringUtils.EMPTY.equals(executeRc.getMessage().trim())) {
                throw new AnalysisExecutionException(Messages.getString("ReportExecutor.failRunAnalysis", analysis.getName(), executeRc.getMessage()));
            }
            // ADD msjian TDQ-5952: we should close connections always
            TdqAnalysisConnectionPool.closeConnectionPool(analysis);
            // TDQ-5952~
            if (!executeRc.isOk()) {
                log.error("Failed to execute analysis " + analysis.getName() + ". Reason: " + executeRc.getMessage());
                atLeastOneFailure = true;
            }
            if (log.isInfoEnabled()) {
                strBuilder.append("Report " + report.getName() + ": Analysis " + analysis.getName() + " refreshed. State: " + executeRc.isOk() + "\n");
            }
        } else {
            // skipped analysis
            if (log.isInfoEnabled()) {
                strBuilder.append("Report " + report.getName() + ": Analysis " + analysis.getName() + " skipped.\n");
            }
        }
    }
    // log execution
    if (log.isInfoEnabled()) {
        if (strBuilder.length() == 0) {
            log.info("Generating reports for \"" + report.getName() + "\" without refreshing any analysis.");
        } else {
            log.info(strBuilder.toString());
        }
    }
    long endTime = System.currentTimeMillis();
    // fill in the execution informations
    ExecutionInformations execInformations = ReportHelper.getExecutionInformations(report);
    execInformations.setExecutionDate(new Date(startTime));
    int duration = (int) (endTime - startTime);
    execInformations.setExecutionDuration(duration);
    execInformations.setExecutionNumber(execInformations.getExecutionNumber() + 1);
    if (atLeastOneFailure) {
        execInformations.setLastRunOk(false);
        // $NON-NLS-1$
        String err = Messages.getString("ReportExecutor.AnalysisExecutionFailed", report.getName());
        execInformations.setMessage(err);
        return new ReturnCode(err, false);
    }
    // else
    execInformations.setLastRunOk(true);
    execInformations.setLastExecutionNumberOk(execInformations.getExecutionNumber());
    execInformations.setMessage(null);
    return new ReturnCode();
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisExecutionException(org.talend.cwm.exception.AnalysisExecutionException) AnalysisMap(org.talend.dataquality.reports.AnalysisMap) Date(java.util.Date)

Example 49 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class SchemaAnalysisExecutor method evaluate.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.analysis.AnalysisExecutor#runAnalysis(org.talend.dataquality.analysis.Analysis,
     * java.lang.String)
     */
@Override
protected ReturnCode evaluate(Analysis analysis, java.sql.Connection connection, String sqlStatement) {
    SchemaEvaluator eval = new SchemaEvaluator();
    // MOD xqliu 2009-02-09 bug 6237
    eval.setMonitor(getMonitor());
    // // --- add indicators
    EList<Indicator> indicators = analysis.getResults().getIndicators();
    for (Indicator indicator : indicators) {
        ModelElement analyzedElement = indicator.getAnalyzedElement();
        if (analyzedElement == null) {
            continue;
        }
        Schema cat = SwitchHelpers.SCHEMA_SWITCH.doSwitch(analyzedElement);
        if (cat == null) {
            continue;
        }
        eval.storeIndicator(cat, indicator);
        // ADDED rli 2008-07-10 fixed for the SchemaIndicator will increased after connection analysis running.
        indicator.reset();
    }
    if (getMonitor() != null) {
        getMonitor().worked(compIndicatorsWorked);
    }
    ReturnCode retCode = runAnalysisLow(analysis, sqlStatement, eval, connection);
    return retCode;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) ReturnCode(org.talend.utils.sugars.ReturnCode) Schema(orgomg.cwm.resource.relational.Schema) SchemaEvaluator(org.talend.dq.indicators.SchemaEvaluator) Indicator(org.talend.dataquality.indicators.Indicator)

Example 50 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ConnectionAnalysisExecutor method evaluate.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.analysis.AnalysisExecutor#runAnalysis(org.talend.dataquality.analysis.Analysis,
     * java.lang.String)
     */
@Override
protected ReturnCode evaluate(Analysis analysis, java.sql.Connection connection, String sqlStatement) {
    ConnectionEvaluator eval = new ConnectionEvaluator();
    // MOD xqliu 2009-02-09 bug 6237
    eval.setMonitor(getMonitor());
    // // --- add indicators
    EList<Indicator> indicators = analysis.getResults().getIndicators();
    for (Indicator indicator : indicators) {
        ModelElement analyzedElement = indicator.getAnalyzedElement();
        if (analyzedElement == null) {
            continue;
        }
        Connection dataProvider = SwitchHelpers.CONNECTION_SWITCH.doSwitch(analyzedElement);
        if (dataProvider == null) {
            continue;
        }
        eval.storeIndicator(dataProvider, indicator);
        // ADDED rli 2008-07-10 fixed for the SchemaIndicator will increased after connection analysis running.
        indicator.reset();
    }
    ReturnCode retCode = runAnalysisLow(analysis, sqlStatement, eval, connection);
    if (getMonitor() != null) {
        getMonitor().worked(compIndicatorsWorked);
    }
    return retCode;
}
Also used : ConnectionEvaluator(org.talend.dq.indicators.ConnectionEvaluator) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) ReturnCode(org.talend.utils.sugars.ReturnCode) Connection(org.talend.core.model.metadata.builder.connection.Connection) Indicator(org.talend.dataquality.indicators.Indicator)

Aggregations

ReturnCode (org.talend.utils.sugars.ReturnCode)175 ArrayList (java.util.ArrayList)42 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)42 Test (org.junit.Test)29 File (java.io.File)26 Connection (org.talend.core.model.metadata.builder.connection.Connection)26 Indicator (org.talend.dataquality.indicators.Indicator)25 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)20 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)18 Analysis (org.talend.dataquality.analysis.Analysis)18 Property (org.talend.core.model.properties.Property)17 IFile (org.eclipse.core.resources.IFile)16 IRepositoryNode (org.talend.repository.model.IRepositoryNode)16 IFolder (org.eclipse.core.resources.IFolder)15 SQLException (java.sql.SQLException)14 PersistenceException (org.talend.commons.exception.PersistenceException)11 TdColumn (org.talend.cwm.relational.TdColumn)11 IOException (java.io.IOException)10 EObject (org.eclipse.emf.ecore.EObject)10 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)10