Search in sources :

Example 21 with IPod

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();
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) Collection(java.util.Collection) IBuild(com.openshift.restclient.model.IBuild) Collectors(java.util.stream.Collectors) Connection(org.jboss.tools.openshift.core.connection.Connection) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) IPod(com.openshift.restclient.model.IPod) List(java.util.List) Window(org.eclipse.jface.window.Window) UIUtils(org.jboss.tools.openshift.internal.common.ui.utils.UIUtils) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) PodLogsJob(org.jboss.tools.openshift.internal.ui.job.PodLogsJob) ConnectionsRegistryUtil(org.jboss.tools.openshift.core.connection.ConnectionsRegistryUtil) ISelection(org.eclipse.jface.viewers.ISelection) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) Collections(java.util.Collections) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) LabelProvider(org.eclipse.jface.viewers.LabelProvider) IContainer(com.openshift.restclient.model.IContainer) ArrayUtils(org.apache.commons.lang.ArrayUtils) PodLogsJob(org.jboss.tools.openshift.internal.ui.job.PodLogsJob) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) IContainer(com.openshift.restclient.model.IContainer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 22 with IPod

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;
}
Also used : IOpenshiftUIElement(org.jboss.tools.openshift.internal.ui.models.IOpenshiftUIElement) ISelectionService(org.eclipse.ui.ISelectionService) OpenShiftImages(org.jboss.tools.openshift.internal.ui.OpenShiftImages) CompoundContributionItem(org.eclipse.ui.actions.CompoundContributionItem) PlatformUI(org.eclipse.ui.PlatformUI) ResourceWrapperUtils(org.jboss.tools.openshift.internal.ui.utils.ResourceWrapperUtils) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) HashMap(java.util.HashMap) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IPod(com.openshift.restclient.model.IPod) UIUtils(org.jboss.tools.openshift.internal.common.ui.utils.UIUtils) MenuItem(org.eclipse.swt.widgets.MenuItem) IWorkbenchContribution(org.eclipse.ui.menus.IWorkbenchContribution) IRunningPodHolder(org.jboss.tools.openshift.internal.ui.models.IRunningPodHolder) Map(java.util.Map) SWT(org.eclipse.swt.SWT) IContributionItem(org.eclipse.jface.action.IContributionItem) ISelection(org.eclipse.jface.viewers.ISelection) IServiceLocator(org.eclipse.ui.services.IServiceLocator) Menu(org.eclipse.swt.widgets.Menu) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem) IOpenshiftUIElement(org.jboss.tools.openshift.internal.ui.models.IOpenshiftUIElement) IService(com.openshift.restclient.model.IService) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IRunningPodHolder(org.jboss.tools.openshift.internal.ui.models.IRunningPodHolder) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService)

Example 23 with IPod

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;
}
Also used : IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IResource(com.openshift.restclient.model.IResource) IPod(com.openshift.restclient.model.IPod) IReplicationController(com.openshift.restclient.model.IReplicationController)

Example 24 with IPod

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;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IPod(com.openshift.restclient.model.IPod)

Example 25 with IPod

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

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