use of org.jboss.tools.openshift.internal.core.server.debug.DebugContext in project jbosstools-openshift by jbosstools.
the class OpenShiftDebugModeTest method debuggingContextShouldDefaultToDefaultDebugPortAndDebuggingNotEnabled.
@Test
public void debuggingContextShouldDefaultToDefaultDebugPortAndDebuggingNotEnabled() {
// given
// when
DebugContext context = new DebugContext(server);
// then
assertThat(context.getDebugPort()).isEqualTo(toInt(DebugContext.DEFAULT_DEBUG_PORT));
assertThat(context.isDebugEnabled()).isFalse();
}
use of org.jboss.tools.openshift.internal.core.server.debug.DebugContext in project jbosstools-openshift by jbosstools.
the class OpenShiftLaunchController method mapPortForwarding.
/**
* Map the remote port to a local port.
* Return the local port in use, or -1 if failed
* @param server
* @param remotePort
* @return the local debug port or -1 if port forwarding did not start or was cancelled.
* @throws CoreException
*/
protected int mapPortForwarding(final DebugContext context, final IProgressMonitor monitor) throws CoreException {
monitor.subTask("Starting port forwarding...");
IPod pod = context.getPod();
if (pod == null) {
throw new CoreException(StatusFactory.errorStatus(OpenShiftCoreActivator.PLUGIN_ID, NLS.bind("Could not find running pod to forward to in server adapter \"{0}\"", getServer().getName())));
}
Set<PortPair> podPorts = PortForwardingUtils.getForwardablePorts(pod);
int remotePort = context.getDebugPort();
if (remotePort == DebugContext.NO_DEBUG_PORT) {
throw new CoreException(StatusFactory.errorStatus(OpenShiftCoreActivator.PLUGIN_ID, NLS.bind("No pod port to forward to specified in server adapter \"{0}\"", getServer().getName())));
}
Optional<PortPair> debugPort = podPorts.stream().filter(p -> remotePort == p.getRemotePort()).findFirst();
if (!debugPort.isPresent()) {
throw new CoreException(StatusFactory.errorStatus(OpenShiftCoreActivator.PLUGIN_ID, NLS.bind("Pod port specified in server adapter \"{0}\" is not present in pod \"{1}\"", getServer().getName(), pod.getName())));
}
if (PortForwardingUtils.isPortForwardingStarted(pod)) {
return debugPort.get().getLocalPort();
}
if (mapPorts(podPorts, monitor)) {
PortForwardingUtils.startPortForwarding(pod, podPorts, IBinaryCapability.SKIP_TLS_VERIFY);
if (PortForwardingUtils.isPortForwardingStarted(pod)) {
return debugPort.get().getLocalPort();
}
}
throw new CoreException(StatusFactory.errorStatus(OpenShiftCoreActivator.PLUGIN_ID, NLS.bind("Could not setup port forwarding to pod \"{0}\" in server adapter \"{1}\"", pod.getName(), getServer().getName())));
}
use of org.jboss.tools.openshift.internal.core.server.debug.DebugContext in project jbosstools-openshift by jbosstools.
the class OpenShiftLaunchController method createDebugContext.
protected DebugContext createDebugContext(OpenShiftServerBehaviour beh, IProgressMonitor monitor) {
monitor.subTask("Initialising debugging...");
DockerImageLabels imageLabels = getDockerImageLabels(beh, monitor);
IServer server = beh.getServer();
String devmodeKey = StringUtils.defaultIfBlank(OpenShiftServerUtils.getDevmodeKey(server), imageLabels.getDevmodeKey());
String debugPortKey = StringUtils.defaultIfBlank(OpenShiftServerUtils.getDebugPortKey(server), imageLabels.getDevmodePortKey());
String debugPort = StringUtils.defaultIfBlank(OpenShiftServerUtils.getDebugPort(server), imageLabels.getDevmodePortValue());
return new DebugContext(beh.getServer(), devmodeKey, debugPortKey, debugPort);
}
use of org.jboss.tools.openshift.internal.core.server.debug.DebugContext in project jbosstools-openshift by jbosstools.
the class OpenShiftLaunchController method startDebugging.
protected void startDebugging(OpenShiftServerBehaviour behaviour, DebugContext context, IProgressMonitor monitor) {
IDebugListener listener = new IDebugListener() {
@Override
public void onDebugChange(DebugContext context, IProgressMonitor monitor) throws CoreException {
int localPort = mapPortForwarding(context, monitor);
ILaunch debuggerLaunch = attachRemoteDebugger(behaviour.getServer(), localPort, monitor);
if (debuggerLaunch != null) {
overrideHotcodeReplace(behaviour.getServer(), debuggerLaunch);
}
}
@Override
public void onPodRestart(DebugContext debuggingContext, IProgressMonitor monitor) throws CoreException {
onDebugChange(debuggingContext, monitor);
}
};
context.setDebugListener(listener);
new OpenShiftDebugMode(context).enableDebugging();
}
use of org.jboss.tools.openshift.internal.core.server.debug.DebugContext in project jbosstools-openshift by jbosstools.
the class OpenShiftLaunchController method stopDebugging.
private void stopDebugging(DebugContext context, IProgressMonitor monitor) {
IDebugListener listener = new IDebugListener() {
@Override
public void onDebugChange(DebugContext context, IProgressMonitor monitor) throws CoreException {
DebugLaunchConfigs configs = DebugLaunchConfigs.get();
if (configs != null) {
configs.terminateRemoteDebugger(getServer());
}
unMapPortForwarding(context.getPod());
}
@Override
public void onPodRestart(DebugContext debuggingContext, IProgressMonitor monitor) throws CoreException {
}
};
context.setDebugListener(listener);
new OpenShiftDebugMode(context).disableDebugging();
}
Aggregations