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;
}
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;
}
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();
}
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;
}
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;
}
Aggregations