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());
}
}
}
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());
}
}
}
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;
}
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;
}
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);
}
Aggregations