Search in sources :

Example 1 with DebugContext

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();
}
Also used : DebugContext(org.jboss.tools.openshift.internal.core.server.debug.DebugContext) Test(org.junit.Test)

Example 2 with DebugContext

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())));
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) PortForwardingUtils(org.jboss.tools.openshift.internal.core.portforwarding.PortForwardingUtils) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) CoreException(org.eclipse.core.runtime.CoreException) IDebugListener(org.jboss.tools.openshift.internal.core.server.debug.IDebugListener) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) DebugException(org.eclipse.debug.core.DebugException) IStatus(org.eclipse.core.runtime.IStatus) Server(org.eclipse.wst.server.core.internal.Server) ILaunch(org.eclipse.debug.core.ILaunch) AbstractSubsystemController(org.jboss.ide.eclipse.as.wtp.core.server.behavior.AbstractSubsystemController) StatusFactory(org.jboss.tools.foundation.core.plugin.log.StatusFactory) SocketUtil(org.eclipse.jdt.launching.SocketUtil) NLS(org.eclipse.osgi.util.NLS) ClassCollectingHCRListener(org.jboss.ide.eclipse.as.core.util.ClassCollectingHCRListener) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) OpenShiftServerBehaviour(org.jboss.tools.openshift.core.server.OpenShiftServerBehaviour) OpenShiftCoreActivator(org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator) ILaunchManager(org.eclipse.debug.core.ILaunchManager) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) IBinaryCapability(com.openshift.restclient.capability.IBinaryCapability) Optional(java.util.Optional) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) IReplicationController(com.openshift.restclient.model.IReplicationController) OpenShiftDebugMode(org.jboss.tools.openshift.internal.core.server.debug.OpenShiftDebugMode) DockerImageLabels(org.jboss.tools.openshift.core.server.DockerImageLabels) IPortForwardable(com.openshift.restclient.capability.resources.IPortForwardable) OpenShiftServerUtils.toCoreException(org.jboss.tools.openshift.core.server.OpenShiftServerUtils.toCoreException) IPod(com.openshift.restclient.model.IPod) ServerProcess(org.jboss.ide.eclipse.as.wtp.core.server.launch.ServerProcess) IProject(org.eclipse.core.resources.IProject) IModule(org.eclipse.wst.server.core.IModule) DebugLaunchConfigs(org.jboss.tools.openshift.internal.core.server.debug.DebugLaunchConfigs) IJavaDebugTarget(org.eclipse.jdt.debug.core.IJavaDebugTarget) IResource(com.openshift.restclient.model.IResource) Job(org.eclipse.core.runtime.jobs.Job) IServer(org.eclipse.wst.server.core.IServer) OpenShiftServerUtils(org.jboss.tools.openshift.core.server.OpenShiftServerUtils) IOException(java.io.IOException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IJavaHotCodeReplaceListener(org.eclipse.jdt.debug.core.IJavaHotCodeReplaceListener) OpenShiftCoreMessages(org.jboss.tools.openshift.core.OpenShiftCoreMessages) Connection(org.jboss.tools.openshift.core.connection.Connection) DebugContext(org.jboss.tools.openshift.internal.core.server.debug.DebugContext) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IDebugTarget(org.eclipse.debug.core.model.IDebugTarget) ILaunchServerController(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ILaunchServerController) ISubsystemController(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ISubsystemController) CoreException(org.eclipse.core.runtime.CoreException) OpenShiftServerUtils.toCoreException(org.jboss.tools.openshift.core.server.OpenShiftServerUtils.toCoreException) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) IPod(com.openshift.restclient.model.IPod)

Example 3 with DebugContext

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);
}
Also used : IServer(org.eclipse.wst.server.core.IServer) DebugContext(org.jboss.tools.openshift.internal.core.server.debug.DebugContext) DockerImageLabels(org.jboss.tools.openshift.core.server.DockerImageLabels)

Example 4 with DebugContext

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();
}
Also used : OpenShiftDebugMode(org.jboss.tools.openshift.internal.core.server.debug.OpenShiftDebugMode) IDebugListener(org.jboss.tools.openshift.internal.core.server.debug.IDebugListener) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILaunch(org.eclipse.debug.core.ILaunch) DebugContext(org.jboss.tools.openshift.internal.core.server.debug.DebugContext)

Example 5 with DebugContext

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();
}
Also used : OpenShiftDebugMode(org.jboss.tools.openshift.internal.core.server.debug.OpenShiftDebugMode) IDebugListener(org.jboss.tools.openshift.internal.core.server.debug.IDebugListener) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DebugLaunchConfigs(org.jboss.tools.openshift.internal.core.server.debug.DebugLaunchConfigs) DebugContext(org.jboss.tools.openshift.internal.core.server.debug.DebugContext)

Aggregations

DebugContext (org.jboss.tools.openshift.internal.core.server.debug.DebugContext)7 OpenShiftDebugMode (org.jboss.tools.openshift.internal.core.server.debug.OpenShiftDebugMode)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IDebugListener (org.jboss.tools.openshift.internal.core.server.debug.IDebugListener)4 IOException (java.io.IOException)2 CoreException (org.eclipse.core.runtime.CoreException)2 DebugException (org.eclipse.debug.core.DebugException)2 ILaunch (org.eclipse.debug.core.ILaunch)2 IServer (org.eclipse.wst.server.core.IServer)2 DockerImageLabels (org.jboss.tools.openshift.core.server.DockerImageLabels)2 IBinaryCapability (com.openshift.restclient.capability.IBinaryCapability)1 IPortForwardable (com.openshift.restclient.capability.resources.IPortForwardable)1 PortPair (com.openshift.restclient.capability.resources.IPortForwardable.PortPair)1 IPod (com.openshift.restclient.model.IPod)1 IReplicationController (com.openshift.restclient.model.IReplicationController)1 IResource (com.openshift.restclient.model.IResource)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 StringUtils (org.apache.commons.lang.StringUtils)1