use of com.openshift.restclient.model.IPod in project jbosstools-openshift by jbosstools.
the class OpenShiftServerUtils method getAllPods.
/**
* Returns all pods for the given server. Returns an empty list otherwise.
*
* @param server
* @return
*/
public static Collection<IPod> getAllPods(IServer server, IProgressMonitor monitor) {
Connection connection = getConnection(server);
if (connection == null) {
return Collections.emptyList();
}
IResource resource = getResource(server, connection, monitor);
if (resource == null) {
return Collections.emptyList();
}
List<IPod> collection = new ArrayList<>();
List<IPod> pods = connection.getResources(ResourceKind.POD, resource.getNamespaceName());
List<IPod> servicePods = ResourceUtils.getPodsFor(resource, pods);
collection.addAll(pods);
collection.addAll(servicePods);
return collection;
}
use of com.openshift.restclient.model.IPod in project jbosstools-openshift by jbosstools.
the class PodLogsHandler method getPodFromBuild.
private IPod getPodFromBuild(ExecutionEvent event) {
IBuild build = getSelectedElement(event, IBuild.class);
if (build != null) {
final String buildName = build.getName();
Connection connection = ConnectionsRegistryUtil.safeGetConnectionFor(build);
List<IPod> pods = connection.getResources(ResourceKind.POD, build.getNamespaceName());
for (IPod pod : pods) {
if (buildName.equals(pod.getAnnotation(OpenShiftAPIAnnotations.BUILD_NAME))) {
return pod;
}
}
}
return null;
}
use of com.openshift.restclient.model.IPod in project jbosstools-openshift by jbosstools.
the class PortForwardingHandler method handleEvent.
@Override
protected void handleEvent(ExecutionEvent event) {
ISelection selection = UIUtils.getCurrentSelection(event);
final IPod pod = UIUtils.getFirstElement(selection, IPod.class);
if (pod == null) {
MessageDialog.openError(HandlerUtil.getActiveShell(event), "No pod selection", "No pod was selected for port forwarding.");
}
openDialog(pod);
}
use of com.openshift.restclient.model.IPod in project jbosstools-openshift by jbosstools.
the class ResourceUtils method getDeploymentConfigFor.
private static IDeploymentConfig getDeploymentConfigFor(IService service, Connection connection) {
if (service == null) {
return null;
}
String dcName = getDeploymentConfigNameFor(service);
if (dcName != null) {
return getDeploymentConfigByName(dcName, service, connection);
} else {
String namespace = service.getNamespaceName();
IReplicationController rc = getReplicationControllerFor(service, connection.getResources(ResourceKind.REPLICATION_CONTROLLER, namespace));
if (rc == null) {
return null;
}
List<IPod> allPods = connection.getResources(ResourceKind.POD, namespace);
List<IPod> pods = allPods.stream().filter(pod -> areRelated((IPod) pod, rc)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(pods)) {
return null;
}
List<IDeploymentConfig> dcs = connection.getResources(ResourceKind.DEPLOYMENT_CONFIG, namespace);
return dcs.stream().filter(dc -> areRelated((IService) service, (IDeploymentConfig) dc, pods)).findFirst().orElse(null);
}
}
use of com.openshift.restclient.model.IPod in project jbosstools-openshift by jbosstools.
the class PortForwardingUtilsTest method shouldStartPortForwardingOnSinglePort.
@Test
@SuppressWarnings("unchecked")
public void shouldStartPortForwardingOnSinglePort() {
// 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);
// when
final IPortForwardable startPortForwarding = PortForwardingUtils.startPortForwarding(pod, port);
// then
assertThat(startPortForwarding).isNotNull().isEqualTo(portForwardable);
assertThat(PortForwardingUtils.isPortForwardingStarted(pod)).isTrue();
}
Aggregations