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);
}
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())));
}
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;
}
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;
}
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");
}
Aggregations