Search in sources :

Example 6 with IPod

use of com.openshift.restclient.model.IPod in project jbosstools-openshift by jbosstools.

the class PortForwardingUtilsTest method shouldGetForwardablePortsOnStartedStopped.

@Test
public void shouldGetForwardablePortsOnStartedStopped() {
    // given
    final IPod pod = Mockito.mock(IPod.class);
    final IPort port = Mockito.mock(IPort.class);
    final IPortForwardable portForwardable = Mockito.mock(IPortForwardable.class);
    Mockito.when(pod.getContainerPorts()).thenReturn(toSet(port));
    // when
    final Set<PortPair> forwardablePorts = PortForwardingUtils.getForwardablePorts(pod);
    // then
    assertThat(forwardablePorts).isNotNull().hasSize(1);
}
Also used : IPort(com.openshift.restclient.model.IPort) IPortForwardable(com.openshift.restclient.capability.resources.IPortForwardable) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) IPod(com.openshift.restclient.model.IPod) Test(org.junit.Test)

Example 7 with IPod

use of com.openshift.restclient.model.IPod 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 8 with IPod

use of com.openshift.restclient.model.IPod in project jbosstools-openshift by jbosstools.

the class OpenshiftJMXConnectionProvider method getJolokiaPort.

protected String getJolokiaPort(IPod pod) {
    String port = "8778";
    IReplicationController rc = ResourceUtils.getDeploymentConfigOrReplicationControllerFor(pod);
    if (rc != null) {
        Optional<IEnvironmentVariable> envPort = rc.getEnvironmentVariables().stream().filter(env -> env.getName().equals("AB_JOLOKIA_PORT")).findFirst();
        if (envPort.isPresent()) {
            port = envPort.get().getValue();
        }
    }
    return port;
}
Also used : IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) IServer(org.eclipse.wst.server.core.IServer) IConnectionProvider(org.jboss.tools.jmx.core.IConnectionProvider) JolokiaConnectionWrapper(org.jboss.tools.jmx.jolokia.JolokiaConnectionWrapper) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) HashMap(java.util.HashMap) AbstractJBossJMXConnectionProvider(org.jboss.ide.eclipse.as.jmx.integration.AbstractJBossJMXConnectionProvider) OpenShiftCoreActivator(org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator) Connection(org.jboss.tools.openshift.core.connection.Connection) ExtensionManager(org.jboss.tools.jmx.core.ExtensionManager) IPod(com.openshift.restclient.model.IPod) List(java.util.List) IEnvironmentVariable(com.openshift.restclient.model.IEnvironmentVariable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Map(java.util.Map) IConnectionWrapper(org.jboss.tools.jmx.core.IConnectionWrapper) Optional(java.util.Optional) IReplicationController(com.openshift.restclient.model.IReplicationController) IEnvironmentVariable(com.openshift.restclient.model.IEnvironmentVariable) IReplicationController(com.openshift.restclient.model.IReplicationController)

Example 9 with IPod

use of com.openshift.restclient.model.IPod in project jbosstools-openshift by jbosstools.

the class OpenshiftJMXConnectionProvider method computeJolokiaURL.

protected String computeJolokiaURL(IServer server) {
    IResource resource = OpenShiftServerUtils.getResource(server, new NullProgressMonitor());
    if (resource != null) {
        String projName = resource.getNamespaceName();
        List<IPod> pods = ResourceUtils.getPodsFor(resource, resource.getProject().getResources(ResourceKind.POD));
        if (!pods.isEmpty()) {
            String podName = pods.get(0).getName();
            String host = server.getHost();
            String portUrlPart = getOpenShiftPort(server);
            String jolokiaPort = getJolokiaPort(pods.get(0));
            return "https://" + host + portUrlPart + "/api/v1/namespaces/" + projName + "/pods/https:" + podName + ":" + jolokiaPort + "/proxy/jolokia/";
        }
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResource(com.openshift.restclient.model.IResource) IPod(com.openshift.restclient.model.IPod)

Example 10 with IPod

use of com.openshift.restclient.model.IPod in project jbosstools-openshift by jbosstools.

the class ResourceUtilsTest method podListWithSeveralDeploymentConfigKeyShouldReturnFirstDeploymentConfigName.

@Test
public void podListWithSeveralDeploymentConfigKeyShouldReturnFirstDeploymentConfigName() {
    // given 2 pods with deployment-config-key label
    HashMap<String, String> podLabels1 = new HashMap<>();
    podLabels1.put("foo", "bar");
    podLabels1.put("bar", "car");
    podLabels1.put(ResourceUtils.DEPLOYMENT_CONFIG, "hooolahoo");
    IPod pod1 = ResourceMocks.createResource(IPod.class, ResourceKind.POD, p -> when(p.getLabels()).thenReturn(podLabels1));
    final HashMap<String, String> podLabels2 = new HashMap<>();
    podLabels2.put("kung", "foo");
    podLabels2.put(ResourceUtils.DEPLOYMENT_CONFIG, "hookaboo");
    IPod pod2 = ResourceMocks.createResource(IPod.class, ResourceKind.POD, p -> when(p.getLabels()).thenReturn(podLabels2));
    List<IPod> pods = Arrays.asList(ResourceMocks.createResource(IPod.class, ResourceKind.POD), pod1, pod2);
    // when
    String name = getDeploymentConfigNameFor(pods);
    // then
    assertThat(name).isEqualTo("hooolahoo");
}
Also used : HashMap(java.util.HashMap) IPod(com.openshift.restclient.model.IPod) Test(org.junit.Test)

Aggregations

IPod (com.openshift.restclient.model.IPod)27 Connection (org.jboss.tools.openshift.core.connection.Connection)11 Test (org.junit.Test)9 IResource (com.openshift.restclient.model.IResource)8 ResourceKind (com.openshift.restclient.ResourceKind)6 IPortForwardable (com.openshift.restclient.capability.resources.IPortForwardable)6 PortPair (com.openshift.restclient.capability.resources.IPortForwardable.PortPair)6 IReplicationController (com.openshift.restclient.model.IReplicationController)6 HashMap (java.util.HashMap)6 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)6 CapabilityVisitor (com.openshift.restclient.capability.CapabilityVisitor)5 Collection (java.util.Collection)5 List (java.util.List)5 Map (java.util.Map)5 ResourceUtils (org.jboss.tools.openshift.internal.core.util.ResourceUtils)5 IBuild (com.openshift.restclient.model.IBuild)4 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)4 IService (com.openshift.restclient.model.IService)4 CoreException (org.eclipse.core.runtime.CoreException)4 ISelection (org.eclipse.jface.viewers.ISelection)4