use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class CreateDatabaseWizard method performFinish.
/**
* Called when user clicks Finish
*
* @return boolean
*/
public boolean performFinish() {
isCanFinished = true;
isOverride = true;
final String databaseName = generalInfoPage.getDatabaseName();
String pageSize = generalInfoPage.getPageSize();
String logPageSize = generalInfoPage.getLogPageSize();
String generalPageNum = generalInfoPage.getGenericPageNum();
String generalVolumePath = generalInfoPage.getGenericVolumePath();
String charset = generalInfoPage.getCharset();
final boolean isAutoStart = generalInfoPage.isAutoStart();
TaskJobExecutor taskExcutor = new TaskJobExecutor() {
public IStatus exec(final IProgressMonitor monitor) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
getShell().setVisible(false);
}
});
if (monitor.isCanceled()) {
isCanFinished = true;
Display.getDefault().syncExec(new Runnable() {
public void run() {
cancel();
close();
}
});
return Status.CANCEL_STATUS;
}
List<String> cubridConfContentList = null;
for (ITask task : taskList) {
if (task instanceof CreateDbTask) {
CreateDbTask createDbTask = (CreateDbTask) task;
createDbTask.setOverwriteConfigFile(isOverride);
} else if (task instanceof SetCubridConfParameterTask) {
if (cubridConfContentList == null) {
continue;
} else {
SetCubridConfParameterTask setParaTask = (SetCubridConfParameterTask) task;
setParaTask.setConfContents(cubridConfContentList);
}
}
task.execute();
final String msg = task.getErrorMsg();
if (monitor.isCanceled()) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
cancel();
close();
}
});
isCanFinished = true;
return Status.CANCEL_STATUS;
}
if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
//start database failed
if (task instanceof CommonUpdateTask && task.getTaskname().equals(CommonTaskName.START_DB_TASK_NAME)) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
CommonUITool.openErrorBox(getShell(), msg + StringUtil.NEWLINE + Messages.createDBFailedMsg);
}
});
return Status.OK_STATUS;
}
Display.getDefault().syncExec(new Runnable() {
public void run() {
CommonUITool.openErrorBox(getShell(), msg);
isCanFinished = false;
getShell().setVisible(true);
}
});
return Status.CANCEL_STATUS;
}
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.getDefault().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.getDefault().syncExec(new Runnable() {
public void run() {
OverrideFileDialog dialog = new OverrideFileDialog(getShell());
dialog.setFiles(files);
isOverride = dialog.open() == IDialogConstants.OK_ID;
getShell().setVisible(!isOverride);
}
});
}
} else if (task instanceof GetCubridConfParameterTask) {
GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
List<String> cubridConfContentListCandidate1 = null;
if (isAutoStart) {
cubridConfContentListCandidate1 = CoreUtils.addDatabaseToServiceServer(getCubridConfParameterTask, null, databaseName);
}
List<String> cubridConfContentListCandidate2 = null;
if (CompatibleUtil.isNeedCheckHAModeOnNewDb(server.getServerInfo())) {
cubridConfContentListCandidate2 = CoreUtils.changeHAModeFromCubridConf(getCubridConfParameterTask, cubridConfContentListCandidate1, databaseName);
}
if (cubridConfContentListCandidate2 == null) {
cubridConfContentList = cubridConfContentListCandidate1;
} else {
cubridConfContentList = cubridConfContentListCandidate2;
}
}
if (!isCanFinished) {
return Status.CANCEL_STATUS;
}
if (monitor.isCanceled()) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
completeAll();
close();
cancel();
}
});
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
public void cancel() {
super.cancel();
GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(server.getServerInfo());
getDatabaseListTask.execute();
boolean isExist = false;
List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
if (databaseInfoList != null) {
for (int i = 0; i < databaseInfoList.size(); i++) {
DatabaseInfo dbInfo = databaseInfoList.get(i);
String dbName = dbInfo.getDbName();
if (dbName.equals(databaseName)) {
isExist = true;
}
}
}
if (isExist) {
CommonUpdateTask deleteTask = new CommonUpdateTask(CommonTaskName.DELETE_DATABASE_TASK_NAME, server.getServerInfo(), CommonSendMsg.getDeletedbSendMsg());
deleteTask.setDbName(databaseName);
deleteTask.setDelbackup(YesNoType.Y);
deleteTask.execute();
}
}
public void done(IJobChangeEvent event) {
if (event.getResult() == Status.OK_STATUS) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
completeAll();
close();
}
});
}
}
};
CheckDirTask checkDirTask = new CheckDirTask(server.getServerInfo());
CheckFileTask checkFileTask = new CheckFileTask(server.getServerInfo());
CreateDbTask createDbTask = new CreateDbTask(server.getServerInfo());
List<String> checkedDirsList = new ArrayList<String>();
List<String> checkedFilesList = new ArrayList<String>();
// add checked directory(general volume path)
addVolumePath(checkedDirsList, generalVolumePath);
String logPageNum = generalInfoPage.getLogPageNum();
String logVolumePath = generalInfoPage.getLogVolumePath();
// add checked directory(log volume path)
addVolumePath(checkedDirsList, logVolumePath);
List<Map<String, String>> volumeList = volumeInfoPage.getVolumeList();
for (int i = 0; i < volumeList.size(); i++) {
Map<String, String> map = volumeList.get(i);
String volumeName = map.get("0");
String volumePath = map.get("4");
// add checked directory(additional volume path)
addVolumePath(checkedDirsList, volumePath);
// add checked file(additional volume)
addVolumePath(checkedFilesList, volumePath + server.getServerInfo().getPathSeparator() + volumeName);
}
String[] dirs = new String[checkedDirsList.size()];
checkDirTask.setDirectory(checkedDirsList.toArray(dirs));
String[] files = new String[checkedFilesList.size()];
checkFileTask.setFile(checkedFilesList.toArray(files));
createDbTask.setDbName(databaseName);
createDbTask.setPageSize(pageSize);
if (logPageSize != null) {
createDbTask.setLogPageSize(logPageSize);
}
if (charset != null) {
createDbTask.setCharset(charset);
}
createDbTask.setNumPage(generalPageNum);
createDbTask.setGeneralVolumePath(generalVolumePath);
createDbTask.setLogSize(logPageNum);
createDbTask.setLogVolumePath(logVolumePath);
createDbTask.setExVolumes(volumeList);
if (!checkedDirsList.isEmpty()) {
taskExcutor.addTask(checkDirTask);
}
if (!checkedFilesList.isEmpty()) {
taskExcutor.addTask(checkFileTask);
}
taskExcutor.addTask(createDbTask);
//add set auto added volume
GetAutoAddVolumeInfo returnInfo = setAutoAddVolumeInfoPage.getAutoAddVolumeInfo();
if (returnInfo != null) {
SetAutoAddVolumeTask setTask = new SetAutoAddVolumeTask(server.getServerInfo());
setTask.setDbname(databaseName);
setTask.setData(returnInfo.getData());
setTask.setDataWarnOutofspace(returnInfo.getData_warn_outofspace());
setTask.setDataExtPage(returnInfo.getData_ext_page());
setTask.setIndex(returnInfo.getIndex());
setTask.setIndexWarnOutofspace(returnInfo.getIndex_warn_outofspace());
setTask.setIndexExtPage(returnInfo.getIndex_ext_page());
taskExcutor.addTask(setTask);
}
GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(server.getServerInfo());
taskExcutor.addTask(getCubridConfParameterTask);
SetCubridConfParameterTask setCubridConfParameterTask = new SetCubridConfParameterTask(server.getServerInfo());
taskExcutor.addTask(setCubridConfParameterTask);
//start database
CommonUpdateTask startDbTask = new CommonUpdateTask(CommonTaskName.START_DB_TASK_NAME, server.getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
startDbTask.setDbName(databaseName);
taskExcutor.addTask(startDbTask);
//set dba password
UpdateAddUserTask updateUserTask = new UpdateAddUserTask(server.getServerInfo(), false);
UserSendObj userSendObj = new UserSendObj();
userSendObj.setDbname(databaseName);
userSendObj.setUsername("dba");
String password = setDbaPasswordPage.getPassword();
userSendObj.setUserpass(password);
updateUserTask.setUserSendObj(userSendObj);
taskExcutor.addTask(updateUserTask);
JobFamily jobFamily = new JobFamily();
String serverName = server.getName();
jobFamily.setServerName(serverName);
String jobName = Messages.msgCreateDbrearJobName + " - " + serverName;
taskExcutor.schedule(jobName, jobFamily, true, Job.SHORT);
//the close is in the job
return false;
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class DatabaseStatusEditor method loadData.
/**
*
* Load data
*
* @return <code>true</code> whether it is successful;<code>false</code>
* otherwise
*/
public boolean loadData() {
TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {
@SuppressWarnings("unchecked")
@Override
public IStatus exec(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
for (ITask t : taskList) {
t.execute();
final String msg = t.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 {
final DbSpaceInfoList dbSpaceInfoList = ((CommonQueryTask<? extends DbSpaceInfoList>) t).getResultModel();
Display.getDefault().syncExec(new Runnable() {
public void run() {
database.getDatabaseInfo().setDbSpaceInfoList(dbSpaceInfoList);
if (scrolledComp == null || scrolledComp.isDisposed()) {
return;
}
initial();
paintComp();
scrolledComp.setContent(parentComp);
scrolledComp.setExpandHorizontal(true);
scrolledComp.setExpandVertical(true);
}
});
}
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
};
CommonQueryTask<? extends DbSpaceInfoList> task = DbSpaceInfoList.useOld(database.getServer().getServerInfo().getEnvInfo()) ? new CommonQueryTask<DbSpaceInfoListOld>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbSpaceInfoListOld()) : new CommonQueryTask<DbSpaceInfoListNew>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbSpaceInfoListNew());
task.setDbName(database.getName());
taskJobExecutor.addTask(task);
String serverName = database.getServer().getName();
String dbName = database.getName();
String jobName = Messages.viewDbStatusJobName + " - " + dbName + "@" + serverName;
taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
return true;
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class UnloadDatabaseDialog method unloadDatabase.
/**
*
* Execute task and unload database
*
* @param buttonId the button id
*/
private void unloadDatabase(final int buttonId) {
isCanFinished = true;
TaskJobExecutor taskExcutor = new TaskJobExecutor() {
private List<String> unloadResultList = null;
public IStatus exec(final IProgressMonitor monitor) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
getShell().setVisible(false);
}
});
if (monitor.isCanceled()) {
cancel();
Display.getDefault().syncExec(new Runnable() {
public void run() {
setReturnCode(buttonId);
close();
}
});
isCanFinished = true;
return Status.CANCEL_STATUS;
}
for (ITask task : taskList) {
task.execute();
final String msg = task.getErrorMsg();
if (monitor.isCanceled()) {
cancel();
Display.getDefault().syncExec(new Runnable() {
public void run() {
setReturnCode(buttonId);
close();
}
});
isCanFinished = true;
return Status.CANCEL_STATUS;
}
if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
getShell().setVisible(true);
}
});
isCanFinished = false;
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.getDefault().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.getDefault().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 UnloadDatabaseTask) {
UnloadDatabaseTask unloadDatabaseTask = (UnloadDatabaseTask) task;
if (!isSchemaOnly) {
unloadResultList = unloadDatabaseTask.getUnloadDbResult();
}
}
if (!isCanFinished) {
return Status.CANCEL_STATUS;
}
if (monitor.isCanceled()) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
setReturnCode(buttonId);
close();
}
});
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
/**
* Notification that a job has completed execution,
*
* @param event the event details
*/
public void done(IJobChangeEvent event) {
if (event.getResult() == Status.OK_STATUS) {
if (isSchemaOnly) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgSuccessUnload);
setReturnCode(buttonId);
close();
}
});
} else {
Display.getDefault().syncExec(new Runnable() {
public void run() {
UnloadDatabaseResultDialog dialog = new UnloadDatabaseResultDialog(getShell());
dialog.setUnloadResulList(unloadResultList);
dialog.open();
setReturnCode(buttonId);
close();
}
});
}
}
}
};
CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
CheckFileTask checkFileTask = new CheckFileTask(database.getServer().getServerInfo());
final UnloadDatabaseTask unloadDatabaseTask = new UnloadDatabaseTask(database.getServer().getServerInfo(), database.getDatabaseInfo().getCharSet());
fillTask(taskExcutor, checkDirTask, checkFileTask, unloadDatabaseTask);
String serverName = database.getServer().getName();
String dbName = database.getName();
String jobName = Messages.msgUnloadDbRearJobName + " - " + dbName + "@" + serverName;
JobFamily jobFamily = new JobFamily();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
taskExcutor.schedule(jobName, jobFamily, true, Job.SHORT);
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class OptimizeDialog method exec.
/**
*
* Execute to optimize the table
*
* @param buttonId the button id
* @param task the task
* @param cancelable whether it is cancelable
* @param shell the shell
*/
public void exec(final int buttonId, final SocketTask task, boolean cancelable, Shell shell) {
TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {
@Override
public IStatus exec(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
for (final ITask t : taskList) {
t.execute();
final String msg = t.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().syncExec(new Runnable() {
public void run() {
TableItem item = new TableItem(volumeTable, SWT.NONE);
if (t.getErrorMsg() == null) {
item.setText(Messages.bind(Messages.errOptimizeSuccess, className.getText()));
} else {
CommonUITool.openInformationBox(getShell(), Messages.titleFailure, Messages.bind(Messages.errOptimizeFail, className.getText(), task.getErrorMsg()));
item.setText(Messages.errOptimizeFail + className.getText() + "-" + task.getErrorMsg());
}
volumeTable.getColumn(0).pack();
}
});
}
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
};
taskJobExecutor.addTask(task);
String serverName = database.getServer().getName();
String dbName = database.getName();
String jobName = Messages.titleOptimizeDbDialog + " - " + dbName + "@" + serverName;
taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class SetDatabaseInfoPage method modifyText.
/**
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
* @param event ModifyEvent
*/
public void modifyText(ModifyEvent event) {
final String port = portText.getText();
String password = passwordText.getText();
String mdbPassword = masteDbaPasswordText.getText();
String distdbPassword = distDbaPasswordText.getText();
boolean isValidPort = ValidateUtil.isNumber(port);
if (isValidPort) {
int portVal = Integer.parseInt(port);
if (portVal < 1024 || portVal > 65535) {
isValidPort = false;
}
}
if (!isValidPort) {
setErrorMessage(Messages.errInvalidPort);
setPageComplete(false);
return;
}
boolean isValidPassword = password.length() >= 4 && password.indexOf(" ") < 0;
if (!isValidPassword) {
setErrorMessage(Messages.errInvalidPassword);
setPageComplete(false);
return;
}
boolean isValidMdbPassword = mdbPassword.length() >= 4 && mdbPassword.indexOf(" ") < 0;
if (!isValidMdbPassword) {
setErrorMessage(Messages.errInvalidMdbPassword);
setPageComplete(false);
return;
}
boolean isValidDistdbPassword = distdbPassword.length() >= 4 && distdbPassword.indexOf(" ") < 0;
if (!isValidDistdbPassword) {
setErrorMessage(Messages.errInvalidDistdbPassword);
setPageComplete(false);
return;
}
boolean isValid = isValidPort && isValidPassword && isValidMdbPassword && isValidDistdbPassword;
setPageComplete(false);
if (isValid) {
final String ip = ipText.getText();
final String userName = userNameText.getText();
final MonitorDashboardPreference monPref = new MonitorDashboardPreference();
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
Display display = getShell().getDisplay();
if (monitor.isCanceled()) {
return false;
}
boolean isConnected = false;
for (ITask task : taskList) {
if (task instanceof MonitoringTask) {
MonitoringTask monitoringTask = (MonitoringTask) task;
monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
isConnected = true;
} else if (task instanceof LoginDatabaseTask) {
task.execute();
}
final String msg = task.getErrorMsg();
if (monitor.isCanceled()) {
if (isConnected) {
ServerManager.getInstance().setConnected(ip, Integer.parseInt(port), userName, false);
}
return false;
}
if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
monitor.done();
display.syncExec(new Runnable() {
public void run() {
setErrorMessage(msg);
}
});
if (isConnected) {
ServerManager.getInstance().setConnected(ip, Integer.parseInt(port), userName, false);
}
return false;
}
}
if (!monitor.isCanceled()) {
if (isConnected) {
ServerManager.getInstance().setConnected(ip, Integer.parseInt(port), userName, false);
}
display.syncExec(new Runnable() {
public void run() {
setErrorMessage(null);
setPageComplete(true);
}
});
}
return true;
}
};
ServerInfo serverInfo = new ServerInfo();
if (ServerManager.getInstance().isConnected(ip, Integer.parseInt(port), userName)) {
serverInfo = CMHostNodePersistManager.getInstance().getServerInfo(ip, Integer.parseInt(port), userName);
} else {
serverInfo.setHostAddress(ip);
serverInfo.setHostMonPort(Integer.parseInt(port));
serverInfo.setHostJSPort(Integer.parseInt(port + 1));
serverInfo.setUserName(userNameText.getText());
serverInfo.setUserPassword(password);
CMHostNodePersistManager.getInstance().addServer(ip, Integer.parseInt(port), userName, serverInfo);
MonitoringTask monitoringTask = new MonitoringTask(serverInfo);
taskExcutor.addTask(monitoringTask);
}
LoginDatabaseTask loginMDbTask = new LoginDatabaseTask(serverInfo);
loginMDbTask.setCMUser("admin");
loginMDbTask.setDbName(masterDbNameText.getText());
loginMDbTask.setDbUser("dba");
loginMDbTask.setDbPassword(masteDbaPasswordText.getText());
taskExcutor.addTask(loginMDbTask);
LoginDatabaseTask loginDistdbTask = new LoginDatabaseTask(replNode.getServer().getServerInfo());
loginDistdbTask.setCMUser("admin");
loginDistdbTask.setDbName(distDbNameText.getText());
loginDistdbTask.setDbUser("dba");
loginDistdbTask.setDbPassword(distDbaPasswordText.getText());
taskExcutor.addTask(loginDistdbTask);
new ExecTaskWithProgress(taskExcutor).exec(true, true);
}
}
Aggregations