Search in sources :

Example 6 with IPortForwardable

use of com.openshift.restclient.capability.resources.IPortForwardable in project jbosstools-openshift by jbosstools.

the class PortForwardingUtils method getForwardablePorts.

/**
 * Returns the {@link PortPair} for the given {@code pod}
 * @param pod the pod to analyze
 * @return an <strong>immutable</strong> {@link Set} of {@link PortPair}
 */
public static Set<IPortForwardable.PortPair> getForwardablePorts(final IPod pod) {
    final Set<IPortForwardable.PortPair> ports = new HashSet<>();
    final IPortForwardable forwardable = REGISTRY.get(pod);
    if (forwardable != null && forwardable.getPortPairs() != null) {
        ports.addAll(forwardable.getPortPairs());
    } else if (pod.getContainerPorts() != null) {
        pod.getContainerPorts().stream().map(containerPort -> new IPortForwardable.PortPair(containerPort)).forEach(portPair -> ports.add(portPair));
    }
    return Collections.unmodifiableSet(ports);
}
Also used : IPortForwardable(com.openshift.restclient.capability.resources.IPortForwardable) OutputStream(java.io.OutputStream) Arrays(java.util.Arrays) MultiStatus(org.eclipse.core.runtime.MultiStatus) IPortForwardable(com.openshift.restclient.capability.resources.IPortForwardable) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) ServerSocket(java.net.ServerSocket) HashSet(java.util.HashSet) IPod(com.openshift.restclient.model.IPod) OCBinaryOperation(org.jboss.tools.openshift.internal.core.OCBinaryOperation) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) Map(java.util.Map) ConnectionsRegistryUtil(org.jboss.tools.openshift.core.connection.ConnectionsRegistryUtil) OpenShiftBinaryOption(com.openshift.restclient.capability.IBinaryCapability.OpenShiftBinaryOption) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) Collections(java.util.Collections) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) HashSet(java.util.HashSet)

Example 7 with IPortForwardable

use of com.openshift.restclient.capability.resources.IPortForwardable in project jbosstools-openshift by jbosstools.

the class PortForwardingUtilsTest method shouldStopPortForwarding.

@Test
@SuppressWarnings("unchecked")
public void shouldStopPortForwarding() throws IOException {
    // given
    final IPod pod = Mockito.mock(IPod.class);
    final PortPair port = Mockito.mock(PortPair.class);
    final IPortForwardable portForwardable = Mockito.mock(IPortForwardable.class);
    Mockito.when(pod.accept(Mockito.any(CapabilityVisitor.class), Mockito.any(IPortForwardable.class))).thenReturn(portForwardable);
    Mockito.when(portForwardable.isForwarding()).thenReturn(true);
    Mockito.when(portForwardable.getPortPairs()).thenReturn(Arrays.asList(port));
    PortForwardingUtils.startPortForwarding(pod, port);
    // when
    final IPortForwardable stopPortForwarding = PortForwardingUtils.stopPortForwarding(pod, null);
    // then
    assertThat(stopPortForwarding).isNotNull().isEqualTo(portForwardable);
    assertThat(PortForwardingUtils.isPortForwardingStarted(pod)).isFalse();
    Mockito.verify(portForwardable, Mockito.times(1)).stop();
}
Also used : IPortForwardable(com.openshift.restclient.capability.resources.IPortForwardable) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) IPod(com.openshift.restclient.model.IPod) Test(org.junit.Test)

Example 8 with IPortForwardable

use of com.openshift.restclient.capability.resources.IPortForwardable in project jbosstools-openshift by jbosstools.

the class PortForwardingUtilsTest method shouldGetForwardablePortsOnStartedState.

@Test
@SuppressWarnings("unchecked")
public void shouldGetForwardablePortsOnStartedState() {
    // given
    final IPod pod = Mockito.mock(IPod.class);
    final PortPair port = Mockito.mock(PortPair.class);
    final IPortForwardable portForwardable = Mockito.mock(IPortForwardable.class);
    Mockito.when(portForwardable.getPortPairs()).thenReturn(Arrays.asList(port));
    Mockito.when(pod.accept(Mockito.any(CapabilityVisitor.class), Mockito.any(IPortForwardable.class))).thenReturn(portForwardable);
    PortForwardingUtils.startPortForwarding(pod, port);
    // when
    final Set<PortPair> forwardablePorts = PortForwardingUtils.getForwardablePorts(pod);
    // then
    assertThat(forwardablePorts).isNotNull().containsExactly(port);
}
Also used : IPortForwardable(com.openshift.restclient.capability.resources.IPortForwardable) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) IPod(com.openshift.restclient.model.IPod) Test(org.junit.Test)

Aggregations

IPortForwardable (com.openshift.restclient.capability.resources.IPortForwardable)8 PortPair (com.openshift.restclient.capability.resources.IPortForwardable.PortPair)5 IPod (com.openshift.restclient.model.IPod)5 CapabilityVisitor (com.openshift.restclient.capability.CapabilityVisitor)4 Test (org.junit.Test)4 IOException (java.io.IOException)2 MessageConsole (org.eclipse.ui.console.MessageConsole)2 MessageConsoleStream (org.eclipse.ui.console.MessageConsoleStream)2 OpenShiftBinaryOption (com.openshift.restclient.capability.IBinaryCapability.OpenShiftBinaryOption)1 IPort (com.openshift.restclient.model.IPort)1 OutputStream (java.io.OutputStream)1 ServerSocket (java.net.ServerSocket)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1