use of org.talend.designer.esb.runcontainer.ui.progress.StopRuntimeProgress in project tesb-studio-se by Talend.
the class RunContainerPreferencePage method initalizeRuntime.
private boolean initalizeRuntime(String location, String host) {
boolean finished = true;
performApply();
ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
try {
dialog.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
SubMonitor totalMonitor = SubMonitor.convert(monitor, 10);
totalMonitor.beginTask("Initializing Runtime server", 10);
// 1. try to stop first
totalMonitor.setTaskName("Stoping Runtime server");
new StopRuntimeProgress().run(totalMonitor);
if (RuntimeServerController.getInstance().getRuntimeProcess() != null && RuntimeServerController.getInstance().getRuntimeProcess().isAlive()) {
RuntimeServerController.getInstance().getRuntimeProcess().waitFor(20, TimeUnit.SECONDS);
}
totalMonitor.worked(2);
// 2. delete data(cannot use JMX to rebootCleanAll as a DLL delete failed)
if (monitor.isCanceled()) {
throw new InterruptedException("Initalize is canceled by user");
}
totalMonitor.setTaskName("Deleting /data folder");
try {
FileUtil.deleteFolder(location + "/data");
} catch (IOException e) {
ExceptionHandler.process(e);
throw new InterruptedException(e.getMessage());
}
if (new File(location + "/data").exists()) {
throw new InterruptedException(RunContainerMessages.getString("RunContainerPreferencePage.InitailzeDialog7"));
}
totalMonitor.worked(1);
// 3. start (again)
if (monitor.isCanceled()) {
throw new InterruptedException("Initalize is canceled by user");
}
totalMonitor.setTaskName("Starting Runtime server");
new StartRuntimeProgress(false).run(totalMonitor);
totalMonitor.worked(2);
// 4. command
if (monitor.isCanceled()) {
throw new InterruptedException("Initalize is canceled by user");
}
File launcher;
String os = System.getProperty("os.name");
if (os != null && os.toLowerCase().contains("windows")) {
launcher = new File(location + "/bin/client.bat");
} else {
launcher = new File(location + "/bin/client");
}
InputStream stream = RunContainerPreferencePage.class.getResourceAsStream("/resources/commands");
File initFile = new File(location + "/scripts/initlocal.sh");
if (!initFile.exists()) {
try {
Files.copy(stream, initFile.toPath());
} catch (IOException e) {
ExceptionHandler.process(e);
throw new InterruptedException(e.getMessage());
}
}
// without username and password is ok
// fixed by KARAF-5019
String command = launcher.getAbsolutePath() + " -h " + host + " -l 1 source file:scripts/initlocal.sh";
RuntimeClientProgress clientProgress = new RuntimeClientProgress(command);
clientProgress.run(totalMonitor);
totalMonitor.done();
}
});
} catch (Throwable e) {
finished = false;
ExceptionHandler.process(e);
IStatus status = new Status(IStatus.ERROR, ESBRunContainerPlugin.PLUGIN_ID, e.getMessage(), e);
if (e.getCause() != null) {
status = new Status(IStatus.ERROR, ESBRunContainerPlugin.PLUGIN_ID, e.getCause().getMessage(), e.getCause());
}
RuntimeErrorDialog.openError(getShell(), RunContainerMessages.getString("RunContainerPreferencePage.InitailzeDialog2"), RunContainerMessages.getString("RunContainerPreferencePage.InitailzeDialog4"), status);
}
return finished;
}
Aggregations