Search in sources :

Example 56 with TaskExecutor

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);
        }
    }
}
Also used : DiagStatusMonitorTemplateDialog(com.cubrid.cubridmanager.ui.monitoring.dialog.DiagStatusMonitorTemplateDialog) CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) StatusTemplateInfo(com.cubrid.cubridmanager.core.monitoring.model.StatusTemplateInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) AddStatusTemplateTask(com.cubrid.cubridmanager.core.monitoring.task.AddStatusTemplateTask)

Example 57 with TaskExecutor

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());
        }
    }
}
Also used : DiagStatusMonitorTemplateDialog(com.cubrid.cubridmanager.ui.monitoring.dialog.DiagStatusMonitorTemplateDialog) CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) StatusTemplateInfo(com.cubrid.cubridmanager.core.monitoring.model.StatusTemplateInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) UpdateStatusTemplateTask(com.cubrid.cubridmanager.core.monitoring.task.UpdateStatusTemplateTask)

Example 58 with TaskExecutor

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();
}
Also used : TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ConnectHostExecutor(com.cubrid.cubridmanager.ui.host.dialog.ConnectHostExecutor) StatisticChartHost(com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartHost)

Example 59 with TaskExecutor

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());
        }
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ReplicationInfo(com.cubrid.cubridmanager.core.replication.model.ReplicationInfo) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SlaveInfo(com.cubrid.cubridmanager.core.replication.model.SlaveInfo) HashSet(java.util.HashSet) Display(org.eclipse.swt.widgets.Display)

Example 60 with TaskExecutor

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());
        }
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ReplicationInfo(com.cubrid.cubridmanager.core.replication.model.ReplicationInfo) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) HashSet(java.util.HashSet) Display(org.eclipse.swt.widgets.Display)

Aggregations

ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)124 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)124 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)81 TreeViewer (org.eclipse.jface.viewers.TreeViewer)38 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)37 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)37 ITask (com.cubrid.common.core.task.ITask)35 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)29 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)25 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)24 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)23 ArrayList (java.util.ArrayList)23 Shell (org.eclipse.swt.widgets.Shell)15 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)14 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)13 DefaultCubridNode (com.cubrid.common.ui.spi.model.DefaultCubridNode)12 IEditorPart (org.eclipse.ui.IEditorPart)12 LogInfo (com.cubrid.cubridmanager.core.logs.model.LogInfo)11 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9