use of com.cubrid.common.ui.spi.progress.TaskExecutor in project cubrid-manager by CUBRID.
the class AddStatusMonitorTemplateAction method run.
/**
* Override the run method in order to open an instance of status monitor
* dialog
*
*/
public void run() {
Object[] obj = this.getSelectedObj();
ICubridNode selection = (ICubridNode) obj[0];
ServerInfo site = selection.getServer().getServerInfo();
boolean execDiagChecked = false;
final GetCMConfParameterTask task = new GetCMConfParameterTask(site);
TaskExecutor taskExec = new CommonTaskExec(null);
taskExec.addTask(task);
new ExecTaskWithProgress(taskExec).exec();
if (!taskExec.isSuccess()) {
return;
}
Map<String, String> confParas = task.getConfParameters();
if (confParas == null) {
execDiagChecked = false;
} else {
if (confParas.get(ConfConstants.EXECUTE_DIAG) == null) {
execDiagChecked = false;
} else {
execDiagChecked = confParas.get(ConfConstants.EXECUTE_DIAG).equals(OnOffType.ON.getText()) ? true : false;
}
}
DiagStatusMonitorTemplateDialog dialog = new DiagStatusMonitorTemplateDialog(getShell());
dialog.setOperation(AddEditType.ADD);
dialog.setSelection(selection);
dialog.setExecDiagChecked(execDiagChecked);
if (dialog.open() == Dialog.OK) {
StatusTemplateInfo statusTemplateInfo = dialog.getStatusTemplateInfo();
AddStatusTemplateTask addTask = new AddStatusTemplateTask(site);
addTask.setStatusTemplateInfo(statusTemplateInfo);
addTask.buildMsg();
String taskName = Messages.bind(Messages.addTemplateTaskName, statusTemplateInfo.getName());
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
taskExecutor.addTask(addTask);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
TreeViewer treeViewer = (TreeViewer) this.getSelectionProvider();
CommonUITool.refreshNavigatorTree(treeViewer, selection);
}
}
}
use of com.cubrid.common.ui.spi.progress.TaskExecutor in project cubrid-manager by CUBRID.
the class EditStatusMonitorTemplateAction method run.
/**
* Override the run method in order to open an instance of status monitor
* dialog
*
*/
public void run() {
Object[] obj = this.getSelectedObj();
ICubridNode selection = (ICubridNode) obj[0];
ServerInfo serverInfo = selection.getServer().getServerInfo();
boolean execDiagChecked = false;
final GetCMConfParameterTask task = new GetCMConfParameterTask(serverInfo);
TaskExecutor taskExec = new CommonTaskExec(null);
taskExec.addTask(task);
new ExecTaskWithProgress(taskExec).exec();
if (!taskExec.isSuccess()) {
return;
}
Map<String, String> confParas = task.getConfParameters();
if (confParas == null) {
execDiagChecked = false;
} else {
if (confParas.get(ConfConstants.EXECUTE_DIAG) == null) {
execDiagChecked = false;
} else {
execDiagChecked = confParas.get(ConfConstants.EXECUTE_DIAG).equals(OnOffType.ON.getText()) ? true : false;
}
}
DiagStatusMonitorTemplateDialog dialog = new DiagStatusMonitorTemplateDialog(getShell());
dialog.setOperation(AddEditType.EDIT);
dialog.setSelection(selection);
dialog.setExecDiagChecked(execDiagChecked);
if (dialog.open() == Dialog.OK) {
StatusTemplateInfo statusTemplateInfo = dialog.getStatusTemplateInfo();
UpdateStatusTemplateTask updateTask = new UpdateStatusTemplateTask(serverInfo);
updateTask.setStatusTemplateInfo(statusTemplateInfo);
updateTask.buildMsg();
String taskName = Messages.bind(Messages.editTemplateTaskName, statusTemplateInfo.getName());
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
taskExecutor.addTask(updateTask);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
TreeViewer treeViewer = (TreeViewer) this.getSelectionProvider();
CommonUITool.refreshNavigatorTree(treeViewer, selection.getParent());
}
}
}
use of com.cubrid.common.ui.spi.progress.TaskExecutor in project cubrid-manager by CUBRID.
the class EditMultiHostStatisticItemDialog method openAddStatisticHostDialog.
private void openAddStatisticHostDialog(StatisticChartHost hostItem, boolean isFirstHost, boolean isNewHost) {
EditStatisticHostDialog dialog = new EditStatisticHostDialog(this.getShell(), this, isNewHost);
if (!isNewHost) {
//initial data when edit host info
dialog.init(type, timeType, hostItem);
}
dialog.setFirstHost(isFirstHost);
if (!isFirstHost) {
StatisticChartHost firstItem = hostList.get(0);
dialog.setFirstMetric(firstItem.getMetric());
dialog.setFirstTime(timeType);
}
ServerInfo serverInfo = null;
if (hostItem != null) {
//edit
serverInfo = LoadMonitorStatisticDataProgress.buildServerInfo(hostItem);
boolean isUnavailable = false;
boolean isSupported = false;
if (serverInfo == null) {
isUnavailable = true;
} else if (serverInfo.isConnected()) {
isSupported = serverInfo.isSupportMonitorStatistic();
} else {
LoadMonitorStatisticDataProgress.addDisconnectedServer(serverInfo);
TaskExecutor taskExcutor = new ConnectHostExecutor(getShell(), serverInfo, true);
((ConnectHostExecutor) taskExcutor).setCheckJdbc(false);
new ExecTaskWithProgress(taskExcutor).exec(true, true);
if (taskExcutor.isSuccess()) {
isSupported = serverInfo.isSupportMonitorStatistic();
} else {
isUnavailable = true;
}
}
dialog.setServerInfo(serverInfo);
if (isUnavailable) {
dialog.setHostStatusValue(dialog.HOST_STATUS_UNAVAILABLE);
} else if (isSupported) {
dialog.setHostStatusValue(dialog.HOST_STATUS_OK);
} else {
dialog.setHostStatusValue(dialog.HOST_STATUS_UNSUPPORTED);
}
}
if (dialog.open() == Dialog.OK) {
if (hostItem != null) {
int oldIndex = hostList.indexOf(hostItem);
hostList.set(oldIndex, dialog.getHostItem());
} else {
hostList.add(dialog.getHostItem());
}
refreshHostTable();
}
enableOk();
}
use of com.cubrid.common.ui.spi.progress.TaskExecutor in project cubrid-manager by CUBRID.
the class StopSlaveDbAction method run.
/**
* Stop database and refresh navigator
*/
public void run() {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj[0])) {
setEnabled(false);
return;
}
final ISchemaNode schemaNode = (ISchemaNode) obj[0];
ReplicationInfo replInfo = (ReplicationInfo) schemaNode.getAdapter(ReplicationInfo.class);
Set<CubridDatabase> databaseSet = new HashSet<CubridDatabase>();
for (int j = 0; j < replInfo.getSlaveList().size(); j++) {
CubridDatabase database = StartSlaveDbAction.getDatabaseByName(schemaNode.getParent(), replInfo.getSlaveList().get(j).getSlaveDbName());
databaseSet.add(database);
}
StringBuffer dbNamesBuffer = new StringBuffer("");
Iterator<SlaveInfo> it = replInfo.getSlaveList().iterator();
while (it.hasNext()) {
dbNamesBuffer.append(it.next().getSlaveDbName()).append(",");
}
String dbNames = dbNamesBuffer.toString().substring(0, dbNamesBuffer.toString().length() - 1);
boolean isStop = CommonUITool.openConfirmBox(getShell(), Messages.bind(Messages.msgConfirmStopDatabase, dbNames));
if (!isStop) {
return;
}
final Object[] dbObjectArr = new Object[databaseSet.size()];
databaseSet.toArray(dbObjectArr);
ISelectionProvider provider = getSelectionProvider();
final Shell shell = getShell();
if (provider instanceof TreeViewer && dbObjectArr.length > 0) {
final TreeViewer viewer = (TreeViewer) provider;
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
Display display = Display.getDefault();
if (monitor.isCanceled()) {
return false;
}
for (int i = 0; i < taskList.size(); i++) {
ISchemaNode node = (ISchemaNode) dbObjectArr[i];
final CubridDatabase database = node.getDatabase();
ITask task = taskList.get(i);
task.execute();
final String msg = task.getErrorMsg();
if (openErrorBox(shell, msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
database.removeAllChild();
if (database.getLoader() != null) {
database.getLoader().setLoaded(false);
}
database.setRunningType(DbRunningType.STANDALONE);
display.syncExec(new Runnable() {
public void run() {
viewer.refresh(database, true);
}
});
if (monitor.isCanceled()) {
return false;
}
}
return true;
}
};
for (int i = 0; i < dbObjectArr.length; i++) {
ISchemaNode node = (ISchemaNode) dbObjectArr[i];
CubridDatabase database = node.getDatabase();
CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.STOP_DB_TASK_NAME, database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
task.setDbName(database.getLabel());
taskExcutor.addTask(task);
}
new ExecTaskWithProgress(taskExcutor).exec();
if (taskExcutor.isSuccess()) {
for (int i = 0; i < dbObjectArr.length; i++) {
CubridDatabase database = (CubridDatabase) dbObjectArr[i];
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_STOP));
}
ActionManager.getInstance().fireSelectionChanged(getSelection());
}
}
}
use of com.cubrid.common.ui.spi.progress.TaskExecutor in project cubrid-manager by CUBRID.
the class StartSlaveDbAction method run.
/**
* Start database and refresh navigator
*/
public void run() {
Object[] obj = this.getSelectedObj();
if (obj == null || obj.length == 0 || !isSupported(obj[0])) {
setEnabled(false);
return;
}
final ISchemaNode schemaNode = (ISchemaNode) obj[0];
ReplicationInfo replInfo = (ReplicationInfo) schemaNode.getAdapter(ReplicationInfo.class);
Set<CubridDatabase> databaseSet = new HashSet<CubridDatabase>();
for (int j = 0; j < replInfo.getSlaveList().size(); j++) {
CubridDatabase database = getDatabaseByName(schemaNode.getParent(), replInfo.getSlaveList().get(j).getSlaveDbName());
databaseSet.add(database);
}
final Object[] dbObjectArr = new Object[databaseSet.size()];
databaseSet.toArray(dbObjectArr);
ISelectionProvider provider = getSelectionProvider();
final Shell shell = getShell();
if (provider instanceof TreeViewer && dbObjectArr.length > 0) {
final TreeViewer viewer = (TreeViewer) provider;
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
Display display = Display.getDefault();
if (monitor.isCanceled()) {
return false;
}
for (int i = 0; i < taskList.size(); i++) {
ISchemaNode node = (ISchemaNode) dbObjectArr[i];
final CubridDatabase database = node.getDatabase();
ITask task = taskList.get(i);
task.execute();
final String msg = task.getErrorMsg();
if (openErrorBox(shell, msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
database.removeAllChild();
if (database.getLoader() != null) {
database.getLoader().setLoaded(false);
}
database.setRunningType(DbRunningType.CS);
display.syncExec(new Runnable() {
public void run() {
viewer.refresh(database, true);
}
});
if (monitor.isCanceled()) {
return false;
}
}
return true;
}
};
for (int i = 0; i < dbObjectArr.length; i++) {
ISchemaNode node = (ISchemaNode) dbObjectArr[i];
CubridDatabase database = node.getDatabase();
CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.START_DB_TASK_NAME, database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
task.setDbName(database.getLabel());
taskExcutor.addTask(task);
}
new ExecTaskWithProgress(taskExcutor).exec();
if (taskExcutor.isSuccess()) {
for (int i = 0; i < dbObjectArr.length; i++) {
CubridDatabase database = (CubridDatabase) dbObjectArr[i];
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_START));
}
ActionManager.getInstance().fireSelectionChanged(getSelection());
}
}
}
Aggregations