use of com.openshift.restclient.model.IPod in project jbosstools-openshift by jbosstools.
the class PodLogsHandler method showLogs.
protected void showLogs(IPod pod, ExecutionEvent event) {
if (pod == null) {
showDialog(event, "No pod selected", "No pod was selected to retrieve a log.");
return;
}
if (!ArrayUtils.contains(STATES, pod.getStatus())) {
showDialog(event, "Logs Unavailable", NLS.bind(INVALID_POD_STATUS_MESSAGE, pod.getStatus()));
return;
}
Collection<IContainer> containers = pod.getContainers();
if (containers.isEmpty()) {
showDialog(event, "Logs Unavailable", "There are no containers from which to retrieve logs");
return;
}
String containerName = null;
if (containers.size() > 1) {
List<String> names = containers.stream().map(c -> c.getName()).collect(Collectors.toList());
Collections.sort(names);
ElementListSelectionDialog dialog = new ElementListSelectionDialog(HandlerUtil.getActiveShell(event), new LabelProvider());
dialog.setElements(names.toArray());
dialog.setTitle("Pod Containers");
dialog.setMessage("Select a pod container");
dialog.setMultipleSelection(false);
int result = dialog.open();
if (Window.CANCEL == result) {
return;
}
containerName = (String) dialog.getFirstResult();
} else if (containers.size() == 1) {
containerName = containers.iterator().next().getName();
}
new PodLogsJob(pod, containerName).schedule();
}
use of com.openshift.restclient.model.IPod in project jbosstools-openshift by jbosstools.
the class ScaleDeploymentContributionItem method isRelevant.
private boolean isRelevant() {
ISelectionService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = service != null ? service.getSelection() : null;
if (selection == null || selection.isEmpty()) {
return false;
}
IRunningPodHolder podHolder = UIUtils.getFirstElement(selection, IRunningPodHolder.class);
if (podHolder == null) {
return false;
}
IOpenshiftUIElement<?, IOpenshiftUIElement<?, ?>> podUIElement = podHolder.getPodUIElement();
if (!(podUIElement instanceof IResourceWrapper)) {
return false;
}
IResourceWrapper<?, ?> podWrapper = (IResourceWrapper<?, ?>) podUIElement;
if (ResourceWrapperUtils.getServiceWrapperFor(podWrapper, serviceWrapper -> ResourceUtils.areRelated((IPod) podWrapper.getWrapped(), (IService) serviceWrapper.getWrapped())) == null) {
return false;
}
return true;
}
use of com.openshift.restclient.model.IPod in project jbosstools-openshift by jbosstools.
the class ScaleDeploymentHandler method getDeploymentConfig.
private IDeploymentConfig getDeploymentConfig(IResourceWrapper<?, ?> wrapper) {
if (wrapper == null) {
return null;
}
IDeploymentConfig dc = null;
IResource wrapped = wrapper.getWrapped();
if (wrapper instanceof IServiceWrapper) {
// service selected
dc = getDeploymentConfig((IServiceWrapper) wrapper);
} else if (wrapped instanceof IPod) {
// pod selected
dc = getDeploymentConfig((IPod) wrapped, wrapper);
} else if (wrapped instanceof IDeploymentConfig) {
// deployment config selected
// has to be tested before IReplicationController, IDeploymentConfig extends IReplicationController
dc = (IDeploymentConfig) wrapped;
} else if (wrapped instanceof IReplicationController) {
// replication controller selected (deployment tab in properties)
// has to be tested after IDeploymentConfig, IDeploymentConfig extends IReplicationController
dc = getDeploymentConfig((IReplicationController) wrapped, wrapper);
}
return dc;
}
use of com.openshift.restclient.model.IPod in project jbosstools-openshift by jbosstools.
the class PortForwardingHandler method getConnection.
@Override
protected IConnection getConnection(ExecutionEvent event) {
ISelection selection = UIUtils.getCurrentSelection(event);
final IPod pod = UIUtils.getFirstElement(selection, IPod.class);
Connection connection = null;
if (pod != null) {
connection = ConnectionsRegistryUtil.safeGetConnectionFor(pod);
}
return connection;
}
use of com.openshift.restclient.model.IPod 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();
}
Aggregations