use of org.eclipse.core.runtime.Status in project cubrid-manager by CUBRID.
the class ConnectHostJobExecutor method exec.
/**
* Execute to connect host
*
* @param monitor the IProgressMonitor
* @return <code>true</code> if successful;<code>false</code>otherwise;
*/
@SuppressWarnings("unchecked")
public IStatus exec(final IProgressMonitor monitor) {
monitor.subTask(Messages.bind(com.cubrid.cubridmanager.ui.mondashboard.Messages.jobConnectHost, serverInfo.getHostAddress()));
isContinue = true;
boolean isRunUpdateCmUserTask = false;
BrokerInfos brokerInfos = null;
errorMsg = null;
for (ITask task : taskList) {
if (task instanceof MonitoringTask) {
IStatus status = connectHost((MonitoringTask) task);
if (Status.OK_STATUS != status) {
return status;
}
} else if ((task instanceof UpdateCMUserTask)) {
updateCMUserAuthInfo(task, isRunUpdateCmUserTask);
} else if ((task instanceof GetHeartbeatNodeInfoTask) && !CompatibleUtil.isSupportHA(serverInfo)) {
continue;
} else {
task.execute();
}
final String msg = task.getErrorMsg();
if (monitor.isCanceled()) {
disConnect();
return Status.CANCEL_STATUS;
}
if (!hostNode.isConnecting()) {
return Status.CANCEL_STATUS;
}
if (msg != null && msg.length() > 0) {
disConnect();
if (isPing) {
errorMsg = msg;
return Status.CANCEL_STATUS;
}
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
}
if (task instanceof GetEnvInfoTask) {
GetEnvInfoTask getEnvInfoTask = (GetEnvInfoTask) task;
EnvInfo envInfo = getEnvInfoTask.loadEnvInfo();
serverInfo.setEnvInfo(envInfo);
String clientVersion = Version.buildVersionId.substring(0, Version.buildVersionId.lastIndexOf("."));
if (!CompatibleUtil.isSupportCMServer(serverInfo, clientVersion)) {
disConnect();
errorMsg = Messages.bind(Messages.errNoSupportServerVersion, clientVersion);
if (isPing) {
return Status.CANCEL_STATUS;
}
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, errorMsg);
}
if (!serverInfo.validateJdbcVersion(serverInfo.getJdbcDriverVersion())) {
disConnect();
if (ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(serverInfo.getJdbcDriverVersion())) {
errorMsg = Messages.errNoSupportDriver;
} else {
errorMsg = Messages.errSelectSupportDriver;
}
if (isPing) {
return Status.CANCEL_STATUS;
}
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, errorMsg);
}
} else if (task instanceof GetDatabaseListTask) {
GetDatabaseListTask getDatabaseListTask = (GetDatabaseListTask) task;
List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
if (databaseInfoList != null) {
allDatabaseInfoList.addAll(databaseInfoList);
}
} else if (task instanceof GetCMConfParameterTask) {
GetCMConfParameterTask getCMConfParameterTask = (GetCMConfParameterTask) task;
Map<String, String> confParameters = getCMConfParameterTask.getConfParameters();
ServerType serverType = ServerType.BOTH;
if (confParameters != null) {
String target = confParameters.get(ConfConstants.CM_TARGET);
if (target != null) {
if (target.indexOf("broker") >= 0 && target.indexOf("server") >= 0) {
serverType = ServerType.BOTH;
} else if (target.indexOf("broker") >= 0) {
serverType = ServerType.BROKER;
} else if (target.indexOf("server") >= 0) {
serverType = ServerType.DATABASE;
}
}
}
if (serverInfo != null) {
serverInfo.setServerType(serverType);
}
} else if (task instanceof CommonQueryTask) {
CommonQueryTask<BrokerInfos> getBrokerTask = (CommonQueryTask<BrokerInfos>) task;
brokerInfos = getBrokerTask.getResultModel();
if (serverInfo != null) {
serverInfo.setBrokerInfos(brokerInfos);
}
} else if (task instanceof GetCMUserListTask) {
if (serverInfo != null && serverInfo.isConnected()) {
GetCMUserListTask getUserInfoTask = (GetCMUserListTask) task;
List<ServerUserInfo> serverUserInfoList = getUserInfoTask.getServerUserInfoList();
for (int i = 0; serverUserInfoList != null && i < serverUserInfoList.size(); i++) {
ServerUserInfo userInfo = serverUserInfoList.get(i);
if (userInfo != null && userInfo.getUserName().equals(serverInfo.getUserName())) {
serverInfo.setLoginedUserInfo(userInfo);
break;
}
}
List<DatabaseInfo> databaseInfoList = serverInfo.getLoginedUserInfo().getDatabaseInfoList();
if (databaseInfoList != null) {
authDatabaseList.addAll(databaseInfoList);
}
isRunUpdateCmUserTask = CubridDatabasesFolderLoader.filterDatabaseList(serverInfo, allDatabaseInfoList, authDatabaseList);
if (isRunUpdateCmUserTask) {
serverInfo.getLoginedUserInfo().setDatabaseInfoList(authDatabaseList);
}
}
} else if (task instanceof GetCubridConfParameterTask) {
GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
Map<String, Map<String, String>> confParas = getCubridConfParameterTask.getConfParameters();
if (serverInfo != null) {
serverInfo.setCubridConfParaMap(confParas);
}
} else if (task instanceof GetBrokerConfParameterTask) {
GetBrokerConfParameterTask getBrokerConfParameterTask = (GetBrokerConfParameterTask) task;
Map<String, Map<String, String>> confParas = getBrokerConfParameterTask.getConfParameters();
if (serverInfo != null) {
serverInfo.setBrokerConfParaMap(confParas);
}
} else if (task instanceof GetHeartbeatNodeInfoTask) {
GetHeartbeatNodeInfoTask getHeartbeatNodeInfoTask = (GetHeartbeatNodeInfoTask) task;
haHostStatusInfo = getHeartbeatNodeInfoTask.getHostStatusInfo(serverInfo.getHostAddress());
}
if (monitor.isCanceled() || !isContinue) {
disConnect();
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
use of org.eclipse.core.runtime.Status in project cubrid-manager by CUBRID.
the class BackupDatabaseDialog method backupDb.
/**
*
* Execute task and backup database
*
* @param buttonId the button id
*/
private void backupDb(final int buttonId) {
isCanFinished = true;
TaskJobExecutor taskExcutor = new TaskJobExecutor() {
private String backupVolInfo;
public IStatus exec(final IProgressMonitor monitor) {
Display display = Display.getDefault();
display.syncExec(new Runnable() {
public void run() {
getShell().setVisible(false);
}
});
if (monitor.isCanceled()) {
cancel();
display.syncExec(new Runnable() {
public void run() {
setReturnCode(buttonId);
close();
}
});
return Status.CANCEL_STATUS;
}
for (ITask task : taskList) {
if (!(task instanceof GetBackupVolInfoTask) || database.getRunningType() != DbRunningType.CS) {
task.execute();
final String msg = task.getErrorMsg();
if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
display.syncExec(new Runnable() {
public void run() {
getShell().setVisible(true);
}
});
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
}
}
if (isCanceled()) {
return Status.CANCEL_STATUS;
}
if (task instanceof CheckDirTask) {
CheckDirTask checkDirTask = (CheckDirTask) task;
final String[] dirs = checkDirTask.getNoExistDirectory();
if (dirs != null && dirs.length > 0) {
display.syncExec(new Runnable() {
public void run() {
CreateDirDialog dialog = new CreateDirDialog(getShell());
dialog.setDirs(dirs);
if (dialog.open() != IDialogConstants.OK_ID) {
isCanFinished = false;
getShell().setVisible(true);
}
}
});
}
} else if (task instanceof CheckFileTask) {
CheckFileTask checkFileTask = (CheckFileTask) task;
final String[] files = checkFileTask.getExistFiles();
if (files != null && files.length > 0) {
display.syncExec(new Runnable() {
public void run() {
OverrideFileDialog dialog = new OverrideFileDialog(getShell());
dialog.setFiles(files);
if (dialog.open() != IDialogConstants.OK_ID) {
isCanFinished = false;
getShell().setVisible(true);
}
}
});
}
} else if (task instanceof GetBackupVolInfoTask && database.getRunningType() == DbRunningType.STANDALONE) {
GetBackupVolInfoTask getBackupVolInfoTask = (GetBackupVolInfoTask) task;
backupVolInfo = getBackupVolInfoTask.getDbBackupVolInfo();
}
if (!isCanFinished) {
return Status.CANCEL_STATUS;
}
if (monitor.isCanceled()) {
cancel();
Display.getDefault().syncExec(new Runnable() {
public void run() {
close();
}
});
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
public void done(IJobChangeEvent event) {
if (event.getResult() == Status.OK_STATUS) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
if (database.getRunningType() == DbRunningType.CS) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgBackupSuccess);
}
});
} else {
if (backupVolInfo != null && backupVolInfo.length() > 0) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
BackupDbVolumeInfoDialog backupDbResultInfoDialog = new BackupDbVolumeInfoDialog(getShell());
backupDbResultInfoDialog.setResultInfoStr(backupVolInfo);
backupDbResultInfoDialog.open();
}
});
}
}
close();
}
});
}
}
};
String backupDir = backupDirText.getText();
CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
checkDirTask.setDirectory(new String[] { backupDir });
CheckFileTask checkFileTask = new CheckFileTask(database.getServer().getServerInfo());
String fileName = backupDirText.getText() + database.getServer().getServerInfo().getPathSeparator() + volumeNameText.getText();
checkFileTask.setFile(new String[] { fileName });
String databaseName = databaseNameText.getText();
String level = backupLevelCombo.getText().replaceAll("Level", "");
String volName = volumeNameText.getText();
boolean isRemoveLog = archiveLogButton.getSelection();
boolean isCheckDbCons = consistentButton.getSelection();
boolean isZip = useCompressButton.getSelection();
boolean isSafeReplication = safeBackupButton.getSelection();
int threadNum = spnThreadNum.getSelection();
BackupDbTask backupDbTask = new BackupDbTask(database.getServer().getServerInfo());
backupDbTask.setDbName(databaseName);
backupDbTask.setLevel(level);
backupDbTask.setVolumeName(volName);
backupDbTask.setBackupDir(backupDir);
backupDbTask.setRemoveLog(isRemoveLog);
backupDbTask.setCheckDatabaseConsist(isCheckDbCons);
backupDbTask.setThreadCount(String.valueOf(threadNum));
backupDbTask.setZiped(isZip);
backupDbTask.setSafeReplication(isSafeReplication);
GetBackupVolInfoTask getBackupVolInfoTask = new GetBackupVolInfoTask(database.getServer().getServerInfo());
getBackupVolInfoTask.setDbName(databaseName);
taskExcutor.addTask(checkDirTask);
taskExcutor.addTask(checkFileTask);
taskExcutor.addTask(backupDbTask);
taskExcutor.addTask(getBackupVolInfoTask);
JobFamily jobFamily = new JobFamily();
String serverName = database.getServer().getName();
String dbName = database.getName();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
String jobName = Messages.msgBackupDBRearJobName + " - " + dbName + "@" + serverName;
taskExcutor.schedule(jobName, jobFamily, true, Job.SHORT);
}
use of org.eclipse.core.runtime.Status in project cubrid-manager by CUBRID.
the class LogEditorPart method connect.
/**
* Each page of log connect
*
* @param isCreateColumn boolean
*
*/
public void connect(final boolean isCreateColumn) {
GetLogListTask task = null;
if (charsetName == null) {
task = new GetLogListTask(this.cubridNode.getServer().getServerInfo());
} else {
task = new GetLogListTask(this.cubridNode.getServer().getServerInfo(), charsetName);
}
task.setPath(path);
task.setStart(Long.toString(lineStart));
task.setEnd(Long.toString(lineEnd));
TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {
public IStatus exec(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
for (final ITask task : taskList) {
task.execute();
final String msg = task.getErrorMsg();
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
} else {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (task instanceof GetLogListTask) {
GetLogListTask getLogListTask = (GetLogListTask) task;
LogContentInfo logContentInfo = (LogContentInfo) getLogListTask.getLogContent();
setTableInfo(logContentInfo, isCreateColumn);
}
}
});
}
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
};
taskJobExecutor.addTask(task);
String jobName = Messages.viewLogJobName + " - " + cubridNode.getName() + "@" + cubridNode.getServer().getName();
taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
}
use of org.eclipse.core.runtime.Status in project cubrid-manager by CUBRID.
the class LogViewAction method run.
/**
* Open the log editor and show log content
*/
public void run() {
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
if (cubridNode == null) {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj[0])) {
setEnabled(false);
return;
}
cubridNode = (ICubridNode) obj[0];
}
LogInfo logInfo = (LogInfo) cubridNode.getAdapter(LogInfo.class);
final String filePath = logInfo.getPath();
TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {
public IStatus exec(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
cubridNode = null;
return Status.CANCEL_STATUS;
}
for (ITask task : taskList) {
task.execute();
final String msg = task.getErrorMsg();
if (monitor.isCanceled()) {
cubridNode = null;
return Status.CANCEL_STATUS;
}
if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
cubridNode = null;
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
}
if (task instanceof CheckFileTask) {
CheckFileTask checkFileTask = (CheckFileTask) task;
final String[] files = checkFileTask.getExistFiles();
if (files == null || files.length == 0) {
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, Messages.bind(Messages.errLogFileNoExist, filePath));
}
} else if (task instanceof GetLogListTask) {
GetLogListTask getLogListTask = (GetLogListTask) task;
final LogContentInfo logContentInfo = (LogContentInfo) getLogListTask.getLogContent();
Display.getDefault().syncExec(new Runnable() {
public void run() {
IEditorPart editorPart = LayoutUtil.getEditorPart(cubridNode, LogEditorPart.ID);
if (editorPart != null) {
window.getActivePage().closeEditor(editorPart, false);
}
try {
IEditorPart editor = window.getActivePage().openEditor(cubridNode, LogEditorPart.ID);
((LogEditorPart) editor).setTableInfo(logContentInfo, true);
} catch (PartInitException e) {
LOGGER.error(e.getMessage(), e);
}
}
});
}
if (monitor.isCanceled()) {
cubridNode = null;
return Status.CANCEL_STATUS;
}
}
cubridNode = null;
return Status.OK_STATUS;
}
};
CheckFileTask checkFileTask = new CheckFileTask(cubridNode.getServer().getServerInfo());
checkFileTask.setFile(new String[] { filePath });
taskJobExecutor.addTask(checkFileTask);
GetLogListTask task = new GetLogListTask(cubridNode.getServer().getServerInfo());
task.setPath(filePath);
task.setStart("1");
task.setEnd("100");
taskJobExecutor.addTask(task);
String jobName = Messages.viewLogJobName + " - " + cubridNode.getName() + "@" + cubridNode.getServer().getName();
taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
}
use of org.eclipse.core.runtime.Status in project cubrid-manager by CUBRID.
the class ImportDataFromFileDialog method finish.
/**
*
* After task finished, call it
*
*
*
*/
private void finish() {
if (getStartShowResult()) {
return;
} else {
setStartShowResult(true);
}
if (importFileHandler instanceof XLSImportFileHandler) {
XLSImportFileHandler xlsHandler = (XLSImportFileHandler) importFileHandler;
xlsHandler.dispose();
} else if (importFileHandler instanceof XLSXImportFileHandler) {
XLSXImportFileHandler xlsHandler = (XLSXImportFileHandler) importFileHandler;
xlsHandler.dispose();
}
long endTimestamp = System.currentTimeMillis();
String spendTime = calcSpendTime(beginTimestamp, endTimestamp);
List<Status> allStatusList = new ArrayList<Status>();
int commitedCount = 0;
boolean isHasError = false;
boolean isCancel = false;
List<String> errorList = new ArrayList<String>();
int totalErrorCount = 0;
for (PstmtDataTask task : taskList) {
commitedCount += task.getCommitedCount();
isCancel = isCancel || task.isCancel();
if (!task.isSuccess() && task.getErrorMsg() != null) {
Status status = new Status(IStatus.ERROR, CommonUIPlugin.PLUGIN_ID, task.getErrorMsg());
allStatusList.add(status);
isHasError = true;
}
errorList.addAll(task.getErrorMsgList());
totalErrorCount = totalErrorCount + task.getTotalErrorCount();
if (!errorList.isEmpty()) {
isHasError = true;
}
}
if (!isHasError && isCancel) {
String msg = Messages.bind(Messages.msgCancelExecSql, new String[] { String.valueOf(commitedCount), spendTime });
CommonUITool.openInformationBox(getShell(), Messages.titleExecuteResult, msg);
close();
deleteLog();
return;
}
String successMsg = Messages.bind(Messages.msgSuccessExecSql, new String[] { String.valueOf(commitedCount), spendTime });
if (!isHasError) {
CommonUITool.openInformationBox(getShell(), Messages.titleExecuteResult, successMsg);
close();
deleteLog();
return;
}
if (errorList.isEmpty()) {
// break
Status status = new Status(IStatus.INFO, CommonUIPlugin.PLUGIN_ID, successMsg + "\r\n");
allStatusList.add(0, status);
IStatus[] errors = new IStatus[allStatusList.size()];
allStatusList.toArray(errors);
MultiStatus multiStatus = new MultiStatus(CommonUIPlugin.PLUGIN_ID, IStatus.OK, errors, Messages.msgDetailCause, null);
String errorMsg = Messages.bind(Messages.errExecSql, new String[] { String.valueOf(commitedCount), spendTime });
ErrorDialog errorDialog = new ErrorDialog(getShell(), Messages.titleExecuteResult, errorMsg, multiStatus, IStatus.INFO | IStatus.ERROR);
errorDialog.open();
if (isHasError) {
getShell().setVisible(true);
} else {
close();
}
} else {
//ignore the error
String msg = Messages.bind(Messages.importColumnNOTotal, String.valueOf(totalErrorCount)) + "\r\n" + successMsg;
ImportResultDialog dialog = new ImportResultDialog(getShell(), msg, errorList, errorLogDir);
dialog.open();
close();
}
deleteLog();
}
Aggregations