Author: adietish
Date: 2011-03-14 07:20:37 -0400 (Mon, 14 Mar 2011)
New Revision: 29750
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/rse/util/RSEUtils.java
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/rse/util/ShowInRemoteSystemExplorerHandler.java
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateRSEFromInstanceJob.java
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateServerFromRSEJob.java
Log:
[JBIDE-8372]
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/rse/util/RSEUtils.java
===================================================================
---
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/rse/util/RSEUtils.java 2011-03-14
09:57:27 UTC (rev 29749)
+++
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/rse/util/RSEUtils.java 2011-03-14
11:20:37 UTC (rev 29750)
@@ -77,11 +77,6 @@
return connectionName;
}
- @Deprecated
- public static String createHostName(DeltaCloudInstance instance) {
- return createRSEHostName(instance);
- }
-
/**
* Returns the RSE host name for the given instance. Returns
* <code>null</code> if the instance is <code>null</null>.
@@ -97,12 +92,6 @@
return instance.getHostName();
}
- @Deprecated
- public static IHost createHost(String connectionName, String hostname, IRSESystemType
systemType,
- ISystemRegistry systemRegistry) throws Exception {
- return createHost("jboss", connectionName, hostname, systemType,
systemRegistry);
- }
-
public static IHost createHost(String username, String connectionName, String hostname,
IRSESystemType systemType,
ISystemRegistry systemRegistry) throws Exception {
// TODO: Internationalize strings
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/rse/util/ShowInRemoteSystemExplorerHandler.java
===================================================================
---
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/rse/util/ShowInRemoteSystemExplorerHandler.java 2011-03-14
09:57:27 UTC (rev 29749)
+++
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/rse/util/ShowInRemoteSystemExplorerHandler.java 2011-03-14
11:20:37 UTC (rev 29750)
@@ -24,7 +24,7 @@
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
import org.jboss.tools.deltacloud.integration.DeltaCloudIntegrationPlugin;
import org.jboss.tools.deltacloud.integration.Messages;
-import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
+import org.jboss.tools.internal.deltacloud.ui.utils.WorkbenchUtils;
/**
* @author Andre Dietisheim
@@ -35,11 +35,13 @@
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
- DeltaCloudInstance instance = UIUtils.getFirstAdaptedElement(selection,
DeltaCloudInstance.class);
+ DeltaCloudInstance instance = WorkbenchUtils.getFirstAdaptedElement(selection,
DeltaCloudInstance.class);
try {
String connectionName = RSEUtils.createConnectionName(instance);
- IHost host = RSEUtils.createHost(connectionName,
- RSEUtils.createHostName(instance),
+ IHost host = RSEUtils.createHost(
+ "jboss",
+ connectionName,
+ RSEUtils.createRSEHostName(instance),
RSEUtils.getSSHOnlySystemType(),
RSEUtils.getSystemRegistry());
Job connectJob = RSEUtils.connect(connectionName,
RSEUtils.getConnectorService(host));
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateRSEFromInstanceJob.java
===================================================================
---
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateRSEFromInstanceJob.java 2011-03-14
09:57:27 UTC (rev 29749)
+++
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateRSEFromInstanceJob.java 2011-03-14
11:20:37 UTC (rev 29750)
@@ -10,15 +10,19 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.integration.wizard;
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.osgi.util.NLS;
import org.eclipse.rse.core.model.IHost;
+import org.eclipse.rse.services.clientserver.messages.SystemOperationFailedException;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
import org.jboss.tools.deltacloud.core.job.AbstractInstanceJob;
@@ -29,33 +33,40 @@
import org.jboss.tools.deltacloud.ui.IDeltaCloudPreferenceConstants;
import org.osgi.service.prefs.Preferences;
+import com.jcraft.jsch.JSchException;
+
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);
+ super(MessageFormat.format("Create RSE {0}", instance.getAlias()), instance,
family);
}
- public IStatus doRun(IProgressMonitor monitor) {
+
+ public IStatus doRun(IProgressMonitor monitor) throws CoreException {
return runRSEJob(getInstance(), monitor);
}
-
+
public void setNextJob(Job job) {
super.setNextJob(job);
this.nextJob2 = job;
}
-
- private IStatus runRSEJob(DeltaCloudInstance instance, IProgressMonitor monitor) {
+
+ private IStatus runRSEJob(DeltaCloudInstance instance, IProgressMonitor monitor) throws
CoreException {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
-
+
String hostname = RSEUtils.createRSEHostName(instance);
if (hostname == null || hostname.length() <= 0) {
return Status.CANCEL_STATUS;
}
-
+
if (isAutoconnect()) {
try {
- monitor.beginTask("Create RSE Server", 100);
+ monitor.beginTask(MessageFormat.format("Create RSE to server {0}",
hostname), 100);
String connectionName = RSEUtils.createConnectionName(instance);
IHost host = RSEUtils.createHost(
"jboss",
@@ -63,31 +74,47 @@
RSEUtils.createRSEHostName(instance),
RSEUtils.getSSHOnlySystemType(),
RSEUtils.getSystemRegistry());
- if( nextJob2 != null && nextJob2 instanceof CreateServerFromRSEJob) {
- ((CreateServerFromRSEJob)nextJob2).setHost(host);
+ if (nextJob2 != null && nextJob2 instanceof CreateServerFromRSEJob) {
+ ((CreateServerFromRSEJob) nextJob2).setHost(host);
}
monitor.worked(10);
-
- SubProgressMonitor submon = new SubProgressMonitor(monitor, 90);
- initialConnect(host);
- return RSEUtils.connect(RSEUtils.getConnectorService(host), 90000, submon);
+ IStatus credentials =
+ triggerCredentialsDialog(host, new SubProgressMonitor(monitor, 10));
+ if (credentials.isOK())
+ return RSEUtils.connect(RSEUtils.getConnectorService(host), CONNECT_TIMEOUT,
+ new SubProgressMonitor(monitor, 80));
+ return credentials;
} catch (Exception e) {
- return new Status(IStatus.ERROR, DeltaCloudIntegrationPlugin.PLUGIN_ID,
- NLS.bind(Messages.COULD_NOT_LAUNCH_RSE_EXPLORER2, instance.getName()), e);
+ throw new CoreException(
+ new Status(IStatus.ERROR, DeltaCloudIntegrationPlugin.PLUGIN_ID,
+ NLS.bind(Messages.COULD_NOT_LAUNCH_RSE_EXPLORER2, instance.getName())));
}
}
return Status.OK_STATUS;
}
-
- private void initialConnect(IHost host) {
+
+ private IStatus triggerCredentialsDialog(IHost host, IProgressMonitor monitor) {
try {
+ monitor.setTaskName(MessageFormat.format("Initiating connection to {0}...",
host.getName()));
IRemoteFileSubSystem system = RSEUtils.findRemoteFileSubSystem(host);
- system.connect(new NullProgressMonitor(), true);
- } catch(Exception e) {
- // ignore, expected, the server probably isn't up yet.
+ system.connect(monitor, true /* force credentials dialog */);
+ } catch (Exception e) {
+ if (e instanceof OperationCanceledException)
+ return Status.CANCEL_STATUS;
+ if (e instanceof SystemOperationFailedException) {
+ Exception f = ((SystemOperationFailedException) e).getRemoteException();
+ if (f != null && f instanceof JSchException) {
+ // User selected No on accept hostkey
+ if (f.getMessage().contains("reject HostKey:"))
+ return Status.CANCEL_STATUS;
+ }
+ }
+ } finally {
+ monitor.done();
}
+ return Status.OK_STATUS;
}
-
+
private boolean isAutoconnect() {
Preferences prefs = new InstanceScope().getNode(Activator.PLUGIN_ID);
boolean autoConnect =
prefs.getBoolean(IDeltaCloudPreferenceConstants.AUTO_CONNECT_INSTANCE, true);
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateServerFromRSEJob.java
===================================================================
---
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateServerFromRSEJob.java 2011-03-14
09:57:27 UTC (rev 29749)
+++
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.integration/src/org/jboss/tools/deltacloud/integration/wizard/CreateServerFromRSEJob.java 2011-03-14
11:20:37 UTC (rev 29750)
@@ -17,6 +17,7 @@
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
+import java.text.MessageFormat;
import java.util.Iterator;
import java.util.Properties;
@@ -81,6 +82,7 @@
public void setHost(IHost host) {
this.host = host;
+ setName(MessageFormat.format("Create Server {0} From RSE Host",
host.getName()));
}
protected IStatus run(IProgressMonitor monitor) {