Author: adietish
Date: 2011-02-10 11:58:07 -0500 (Thu, 10 Feb 2011)
New Revision: 29104
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/rse/util/RSEUtils.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateRSEFromInstanceJob.java
Log:
[JBIDE-8354] removed case where null-status was returned, decreased timeout to 3 minutes,
now reporting real lapse of time (was: simple stepwise increase),
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/rse/util/RSEUtils.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/rse/util/RSEUtils.java 2011-02-10
16:37:03 UTC (rev 29103)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/rse/util/RSEUtils.java 2011-02-10
16:58:07 UTC (rev 29104)
@@ -32,6 +32,7 @@
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PartInitException;
+import org.jboss.tools.common.log.StatusFactory;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
import org.jboss.tools.deltacloud.integration.DeltaCloudIntegrationPlugin;
import org.jboss.tools.deltacloud.integration.Messages;
@@ -43,6 +44,7 @@
*/
public class RSEUtils {
+ private static final int RECONNECT_WAIT = 1000;
private static final String VIEW_REMOTESYSEXPLORER_ID =
"org.eclipse.rse.ui.view.systemView";
public static IRSESystemType getSSHOnlySystemType() {
@@ -104,40 +106,62 @@
}
public static IStatus connect(IConnectorService service, IProgressMonitor monitor)
throws Exception {
- monitor.worked(1);
service.connect(monitor);
- monitor.done();
return Status.OK_STATUS;
}
-
- public static IStatus connect(IConnectorService service, int timeout, IProgressMonitor
monitor) {
- monitor.beginTask("Connecting to remote server", timeout);
+
+ /**
+ * Connects to the given service with the given timeout. Progress will be
+ * reported on the given monitor.
+ *
+ * @param service
+ * the service to connect to
+ * @param timeout
+ * the timeout to apply
+ * @param monitor
+ * the monitor
+ * @return the restult of the connection attempt
+ */
+ public static IStatus connect(IConnectorService service, long timeout, IProgressMonitor
monitor) {
+ long start = System.currentTimeMillis();
+ double scale = (double) 100 / timeout;
+ long current = start;
+ long last = start;
+ monitor.beginTask("Connecting to remote server", 100);
monitor.setTaskName("Connecting to remote server");
- IStatus status = null;
- int count = 0;
- while( status == null && count < timeout && !monitor.isCanceled())
{
+ while (!monitor.isCanceled()) {
+ current = System.currentTimeMillis();
try {
- status = connect(service, monitor);
+ return connect(service, monitor);
+ } catch (OperationCanceledException oce) {
monitor.done();
- return status;
- } catch(OperationCanceledException oce) {
- monitor.done();
return Status.CANCEL_STATUS;
- } catch(Exception e) {
- count += 1000;
- monitor.worked(1000);
- try {
- Thread.sleep(1000);
- } catch(InterruptedException ie) {
+ } catch (Exception e) {
+ monitor.worked(getProgress(current, last, scale));
+ last = current;
+ if (current < start + timeout) {
+ try {
+ Thread.sleep(RECONNECT_WAIT);
+ } catch (InterruptedException ie) {
+ break;
+ }
+ } else {
+ monitor.done();
+ return StatusFactory.getInstance(IStatus.ERROR,
DeltaCloudIntegrationPlugin.PLUGIN_ID,
+ MessageFormat.format("Could not connect to remote server {0}",
service.getHostName()), e);
}
+
}
}
- monitor.done();
- return status;
+ return Status.CANCEL_STATUS;
}
-
-
- public static Job connect(String connectionName, final IConnectorService service)
+
+ private static int getProgress(long current, long last, double scale) {
+ double progress = (current - last) * scale;
+ return (int) Math.floor(progress);
+ }
+
+ public static Job connect(final String connectionName, final IConnectorService service)
throws Exception {
// TODO: internationalize strings
Assert.isLegal(connectionName != null,
@@ -148,10 +172,15 @@
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- return connect(service, monitor);
- } catch(Exception e) {
+ monitor.beginTask(NLS.bind(Messages.RSE_CONNECTING_MESSAGE, connectionName),
+ IProgressMonitor.UNKNOWN);
+ IStatus status = connect(service, monitor);
+ monitor.done();
+ return status;
+ } catch (Exception e) {
e.printStackTrace();
- // odd behavior: service reports connection failure even if things seem to work
(view opens up with connection in it)
+ // odd behavior: service reports connection failure even if
+ // things seem to work (view opens up with connection in it)
// ignore errors since things work
//
// return StatusFactory.getInstance(IStatus.ERROR,
@@ -186,8 +215,9 @@
} catch (PartInitException e) {
// I have no idea wtf is wrong here
// but my dev environment will not let me use common classes
-// IStatus status = StatusFactory.getInstance(IStatus.ERROR,
-// DeltaCloudIntegrationPlugin.PLUGIN_ID, e.getMessage(), e);
+ // IStatus status = StatusFactory.getInstance(IStatus.ERROR,
+ // DeltaCloudIntegrationPlugin.PLUGIN_ID, e.getMessage(),
+ // e);
Status status = new Status(IStatus.ERROR, DeltaCloudIntegrationPlugin.PLUGIN_ID,
e.getMessage(), e);
ErrorDialog.openError(WorkbenchUtils.getActiveShell(),
Messages.ERROR,
@@ -197,7 +227,7 @@
}
});
}
-
+
public static IRemoteFileSubSystem findRemoteFileSubSystem(IHost host) {
return CreateServerFromRSEJob.findRemoteFileSubSystem(host);
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateRSEFromInstanceJob.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateRSEFromInstanceJob.java 2011-02-10
16:37:03 UTC (rev 29103)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateRSEFromInstanceJob.java 2011-02-10
16:58:07 UTC (rev 29104)
@@ -12,7 +12,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
@@ -31,6 +30,9 @@
import org.osgi.service.prefs.Preferences;
public class CreateRSEFromInstanceJob extends AbstractInstanceJob {
+ /** the timeout for trying to connect to the new instance */
+ private static final long CONNECT_TIMEOUT = 3 * 60 * 1000;
+
private Job nextJob2 = null;
public CreateRSEFromInstanceJob(DeltaCloudInstance instance, String family) {
super("Create RSE Host from DeltaCloud Instance", instance, family);
@@ -58,10 +60,8 @@
((CreateServerFromRSEJob)nextJob2).setHost(host);
}
monitor.worked(10);
-
- SubProgressMonitor submon = new SubProgressMonitor(monitor, 90);
- initialConnect(host);
- return RSEUtils.connect(RSEUtils.getConnectorService(host), 90000, submon);
+ triggerCredentialsDialog(host, new SubProgressMonitor(monitor, 10));
+ return RSEUtils.connect(RSEUtils.getConnectorService(host), CONNECT_TIMEOUT, new
SubProgressMonitor(monitor, 80));
} catch (Exception e) {
return ErrorUtils.handleError(Messages.ERROR,
NLS.bind(Messages.COULD_NOT_LAUNCH_RSE_EXPLORER2, instance.getName()),
@@ -71,12 +71,14 @@
return Status.OK_STATUS;
}
- private void initialConnect(IHost host) {
+ private void triggerCredentialsDialog(IHost host, IProgressMonitor monitor) {
try {
IRemoteFileSubSystem system = RSEUtils.findRemoteFileSubSystem(host);
- system.connect(new NullProgressMonitor(), true);
+ system.connect(monitor, true /* force credentials dialog */);
} catch(Exception e) {
// ignore, expected, the server probably isn't up yet.
+ } finally {
+ monitor.done();
}
}