Search in sources :

Example 1 with PodLogsJob

use of org.jboss.tools.openshift.internal.ui.job.PodLogsJob 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)

Aggregations

ResourceKind (com.openshift.restclient.ResourceKind)1 IBuild (com.openshift.restclient.model.IBuild)1 IContainer (com.openshift.restclient.model.IContainer)1 IPod (com.openshift.restclient.model.IPod)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ArrayUtils (org.apache.commons.lang.ArrayUtils)1 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 ISelection (org.eclipse.jface.viewers.ISelection)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 Window (org.eclipse.jface.window.Window)1 NLS (org.eclipse.osgi.util.NLS)1 ElementListSelectionDialog (org.eclipse.ui.dialogs.ElementListSelectionDialog)1 HandlerUtil (org.eclipse.ui.handlers.HandlerUtil)1 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)1 OpenShiftAPIAnnotations (org.jboss.tools.openshift.core.OpenShiftAPIAnnotations)1 Connection (org.jboss.tools.openshift.core.connection.Connection)1