Search in sources :

Example 36 with ITask

use of com.cubrid.common.core.task.ITask 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 37 with ITask

use of com.cubrid.common.core.task.ITask 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)

Example 38 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class CreateReplicationJobExecutor method createDistributor.

/**
	 * create distributor database
	 * 
	 * @param dbName String
	 * @param monitor IProgressMonitor
	 * @param taskList List<ITask>
	 * @return status
	 */
private IStatus createDistributor(String dbName, final IProgressMonitor monitor, List<ITask> taskList) {
    monitor.subTask(Messages.bind(Messages.createDistJobName, dbName));
    Display display = Display.getDefault();
    MonitoringTask monitoringTask = null;
    boolean isExecuteStopDbTask = true;
    MonitorDashboardPreference monPref = new MonitorDashboardPreference();
    for (ITask task : taskList) {
        if (task instanceof MonitoringTask) {
            monitoringTask = (MonitoringTask) task;
            ServerInfo serverInfo = monitoringTask.getServerInfo();
            CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
            monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
        } else if (task instanceof CommonUpdateTask && task.getTaskname().equals(CommonTaskName.STOP_DB_TASK_NAME)) {
            if (isDeleteDb && isExecuteStopDbTask) {
                task.execute();
            } else {
                continue;
            }
        } else if (task instanceof CommonUpdateTask && task.getTaskname().equals(CommonTaskName.DELETE_DATABASE_TASK_NAME)) {
            if (isDeleteDb) {
                task.execute();
            } else {
                continue;
            }
        } else {
            task.execute();
        }
        if (monitor.isCanceled()) {
            disConnect(monitoringTask);
            return Status.CANCEL_STATUS;
        }
        final String msg = task.getErrorMsg();
        if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
            disConnect(monitoringTask);
            return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
        }
        if (task instanceof GetDatabaseListTask) {
            GetDatabaseListTask getDatabaseListTask = (GetDatabaseListTask) task;
            final String distdbName = (String) getDatabaseListTask.getData("dbName");
            List<DatabaseInfo> dbInfoList = getDatabaseListTask.loadDatabaseInfo();
            boolean isDbExist = false;
            for (int i = 0; i < dbInfoList.size(); i++) {
                DatabaseInfo dbInfo = dbInfoList.get(i);
                if (dbName.equalsIgnoreCase(dbInfo.getDbName())) {
                    isDbExist = true;
                    display.syncExec(new Runnable() {

                        public void run() {
                            isDeleteDb = CommonUITool.openConfirmBox(Messages.bind(Messages.msgConfirmDeleteDb, distdbName));
                        }
                    });
                    if (dbInfo.getRunningType() == DbRunningType.CS) {
                        isExecuteStopDbTask = true;
                    }
                    break;
                }
            }
            if (isDbExist && !isDeleteDb) {
                disConnect(monitoringTask);
                return Status.CANCEL_STATUS;
            }
        }
    }
    disConnect(monitoringTask);
    isDeleteDb = false;
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) MonitorDashboardPreference(com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) Display(org.eclipse.swt.widgets.Display)

Example 39 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class CreateReplicationJobExecutor method startReplServer.

/**
	 * start replication server
	 * 
	 * @param serverName String
	 * @param monitor IProgressMonitor
	 * @param taskList List<ITask
	 * @return status
	 */
private IStatus startReplServer(String serverName, final IProgressMonitor monitor, List<ITask> taskList) {
    monitor.subTask(Messages.bind(Messages.startReplServerJobName, serverName));
    MonitoringTask monitoringTask = null;
    MonitorDashboardPreference monPref = new MonitorDashboardPreference();
    for (ITask task : taskList) {
        if (task instanceof MonitoringTask) {
            monitoringTask = (MonitoringTask) task;
            ServerInfo serverInfo = monitoringTask.getServerInfo();
            CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
            monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
        } else {
            task.execute();
        }
        if (monitor.isCanceled()) {
            disConnect(monitoringTask);
            return Status.CANCEL_STATUS;
        }
        final String msg = task.getErrorMsg();
        if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
            disConnect(monitoringTask);
            return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
        }
    }
    disConnect(monitoringTask);
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) MonitorDashboardPreference(com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference) ITask(com.cubrid.common.core.task.ITask) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask)

Example 40 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class ServiceDashboardEditor method loadServerEnvInfo.

/**
	 * Load Server Environment Info
	 */
private void loadServerEnvInfo(final ServerInfo serverInfo, final String key) {
    if (serverInfo.isConnected() == false) {
        return;
    }
    final GetEnvInfoTask getEnvInfoTask = new GetEnvInfoTask(serverInfo);
    TaskJobExecutor taskJobExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {

        public void completeAll() {
            Object input = serviceTreeViewer.getInput();
            ServiceDashboardInfo sDashInfo = getSelectedDashInfo(input, serverInfo.getServerName(), key);
            EnvInfo envInfo = getEnvInfoTask.loadEnvInfo();
            setEnvData(sDashInfo, envInfo);
            serviceTreeViewer.refresh(input);
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    taskJobExec.addTask(getEnvInfoTask);
    executeTask(taskJobExec, serverInfo.getServerName(), Messages.taskGetServerEnvInfo);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) GetEnvInfoTask(com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask) EnvInfo(com.cubrid.cubridmanager.core.common.model.EnvInfo)

Aggregations

ITask (com.cubrid.common.core.task.ITask)85 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)49 IStatus (org.eclipse.core.runtime.IStatus)37 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)35 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)35 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)28 ArrayList (java.util.ArrayList)27 Status (org.eclipse.core.runtime.Status)23 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)20 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)17 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)15 Map (java.util.Map)15 Display (org.eclipse.swt.widgets.Display)15 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)14 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)14 List (java.util.List)14 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)13 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)13 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)12 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)11