Author: xcoulon
Date: 2012-04-27 08:56:39 -0400 (Fri, 27 Apr 2012)
New Revision: 40566
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardModel.java
Log:
Fixed - JBIDE-11073
OpenShift Express Tool: Create a way to invoke rhc-port-forward functionality which
enables users to debug their cloud environments with their local tools
using a 'free port' to avoid duplicate, naming the message console
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardModel.java 2012-04-27
12:20:35 UTC (rev 40565)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardModel.java 2012-04-27
12:56:39 UTC (rev 40566)
@@ -4,9 +4,15 @@
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.launching.SocketUtil;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.console.IConsoleConstants;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
+import org.eclipse.ui.views.IViewDescriptor;
+import org.eclipse.ui.views.IViewRegistry;
import org.jboss.tools.common.databinding.ObservablePojo;
import org.jboss.tools.openshift.express.internal.ui.console.ConsoleUtils;
@@ -54,8 +60,8 @@
if (this.application.isPortFowardingStarted()) {
return;
}
- final MessageConsole console = ConsoleUtils.findMessageConsole(application.getUUID());
- ConsoleUtils.displayConsoleView(console);
+
+ final MessageConsole console =
ConsoleUtils.findMessageConsole(getMessageConsoleName());
MessageConsoleStream stream = console.newMessageStream();
stream.println("Starting port-forwarding...");
this.application.startPortForwarding();
@@ -63,15 +69,22 @@
stream.println(" " + getPortStatus(port));
}
stream.println("done.");
+ ConsoleUtils.displayConsoleView(console);
firePropertyChange(PROPERTY_PORT_FORWARDING, false,
this.application.isPortFowardingStarted());
}
+ /**
+ * @return
+ */
+ private String getMessageConsoleName() {
+ return "Port forwarding for application '" + application.getName() +
"' (" + application.getDomain().getId() + ")";
+ }
+
public void stopPortForwarding() throws OpenShiftSSHOperationException {
if (!this.application.isPortFowardingStarted()) {
return;
}
- final MessageConsole console = ConsoleUtils.findMessageConsole(application.getUUID());
- ConsoleUtils.displayConsoleView(console);
+ final MessageConsole console =
ConsoleUtils.findMessageConsole(getMessageConsoleName());
MessageConsoleStream stream = console.newMessageStream();
stream.println("Stopping port-forwarding...");
this.application.stopPortForwarding();
@@ -79,6 +92,7 @@
stream.println(" " + getPortStatus(port));
}
stream.println("done.");
+ ConsoleUtils.displayConsoleView(console);
firePropertyChange(PROPERTY_PORT_FORWARDING, true,
this.application.isPortFowardingStarted());
}
@@ -144,21 +158,24 @@
// update local bindings while avoiding duplicates
for (IApplicationPortForwarding port : ports) {
// find duplicate
- String key = null;
- int remotePort = port.getRemotePort();
- while (key == null || bindings.contains(key)) {
- if (useFreePorts) {
- port.setLocalPort(SocketUtil.findFreePort());
- } else {
- port.setLocalPort(remotePort);
- }
- key = port.getRemotePort() + ":" + port.getLocalPort();
- remotePort++;
+ port.setLocalPort(port.getRemotePort());
+ String key = computeKey(port);
+ while (bindings.contains(key)) {
+ port.setLocalPort(SocketUtil.findFreePort());
+ key = computeKey(port);
}
bindings.add(key);
}
}
+ /**
+ * @param port
+ * @return
+ */
+ private String computeKey(IApplicationPortForwarding port) {
+ return port.getLocalAddress() + ":" + port.getLocalPort();
+ }
+
public void loadForwardablePorts() throws OpenShiftSSHOperationException {
getApplication().getForwardablePorts();
refreshForwardablePorts();
Show replies by date