Search in sources :

Example 1 with TaskRunNode

use of com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode in project intellij-tekton by redhat-developer.

the class TreeHelper method getYAMLAndKindFromNode.

/**
 * Get YAML and Tekton kind from Tekton tree node.
 *
 * @param node the Tekton tree node
 * @return Pair where 'first' is YAML content and 'second' is Tekton kind
 */
public static Pair<String, String> getYAMLAndKindFromNode(ParentableNode<?> node) {
    Pair<String, String> yamlAndKind = null;
    try {
        String namespace = node.getNamespace();
        Tkn tkncli = node.getRoot().getTkn();
        String content = "";
        String kind = "";
        if (node instanceof PipelineNode) {
            content = tkncli.getPipelineYAML(namespace, node.getName());
            kind = KIND_PIPELINES;
        } else if (node instanceof ResourceNode) {
            content = tkncli.getResourceYAML(namespace, node.getName());
            kind = KIND_RESOURCES;
        } else if (node instanceof TaskNode) {
            content = tkncli.getTaskYAML(namespace, node.getName());
            kind = KIND_TASKS;
        } else if (node instanceof ClusterTaskNode) {
            content = tkncli.getClusterTaskYAML(node.getName());
            kind = KIND_CLUSTERTASKS;
        } else if (node instanceof ConditionNode) {
            content = tkncli.getConditionYAML(namespace, node.getName());
            kind = KIND_CONDITIONS;
        } else if (node instanceof TriggerTemplateNode) {
            content = tkncli.getTriggerTemplateYAML(namespace, node.getName());
            kind = KIND_TRIGGERTEMPLATES;
        } else if (node instanceof TriggerBindingNode) {
            content = tkncli.getTriggerBindingYAML(namespace, node.getName());
            kind = KIND_TRIGGERBINDINGS;
        } else if (node instanceof ClusterTriggerBindingNode) {
            content = tkncli.getClusterTriggerBindingYAML(node.getName());
            kind = KIND_CLUSTERTRIGGERBINDINGS;
        } else if (node instanceof EventListenerNode) {
            content = tkncli.getEventListenerYAML(namespace, node.getName());
            kind = KIND_EVENTLISTENERS;
        } else if (node instanceof TaskRunNode) {
            content = tkncli.getTaskRunYAML(namespace, node.getName());
            kind = KIND_TASKRUN;
        } else if (node instanceof PipelineRunNode) {
            content = tkncli.getPipelineRunYAML(namespace, node.getName());
            kind = KIND_PIPELINERUN;
        }
        yamlAndKind = Pair.create(content, kind);
    } catch (IOException e) {
        UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Error"));
    }
    return yamlAndKind;
}
Also used : ClusterTriggerBindingNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTriggerBindingNode) TriggerBindingNode(com.redhat.devtools.intellij.tektoncd.tree.TriggerBindingNode) TaskNode(com.redhat.devtools.intellij.tektoncd.tree.TaskNode) ClusterTaskNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTaskNode) EventListenerNode(com.redhat.devtools.intellij.tektoncd.tree.EventListenerNode) ClusterTaskNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTaskNode) ClusterTriggerBindingNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTriggerBindingNode) IOException(java.io.IOException) PipelineNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineNode) TriggerTemplateNode(com.redhat.devtools.intellij.tektoncd.tree.TriggerTemplateNode) ResourceNode(com.redhat.devtools.intellij.tektoncd.tree.ResourceNode) PipelineRunNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode) Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) ConditionNode(com.redhat.devtools.intellij.tektoncd.tree.ConditionNode) TaskRunNode(com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode)

Example 2 with TaskRunNode

use of com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode in project intellij-tekton by redhat-developer.

the class CancelAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
    ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_START_STOP + "cancel");
    ExecHelper.submit(() -> {
        ParentableNode element = getElement(selected);
        String namespace = element.getNamespace();
        try {
            if (element instanceof PipelineRunNode) {
                tkncli.cancelPipelineRun(namespace, element.getName());
                telemetry.property(TelemetryService.PROP_RESOURCE_KIND, Constants.KIND_PIPELINERUN).send();
            } else if (element instanceof TaskRunNode) {
                tkncli.cancelTaskRun(namespace, element.getName());
                telemetry.property(TelemetryService.PROP_RESOURCE_KIND, Constants.KIND_TASKRUN).send();
            }
        } catch (IOException e) {
            telemetry.error(anonymizeResource(element.getName(), namespace, e.getMessage())).send();
            Notification notification = new Notification(NOTIFICATION_ID, "Error", element.getName() + " in namespace " + namespace + " failed to cancel\n" + e.getLocalizedMessage(), NotificationType.ERROR);
            Notifications.Bus.notify(notification);
            logger.warn("Error: " + e.getLocalizedMessage(), e);
        }
    });
}
Also used : ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) TaskRunNode(com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode) IOException(java.io.IOException) Notification(com.intellij.notification.Notification) PipelineRunNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode)

Example 3 with TaskRunNode

use of com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode in project intellij-tekton by redhat-developer.

the class MirrorStartAction method createModel.

@Override
protected StartResourceModel createModel(ParentableNode element, String namespace, Tkn tkncli, List<Resource> resources, List<String> serviceAccounts, List<String> secrets, List<String> configMaps, List<String> persistentVolumeClaims) throws IOException {
    String configuration = "", runConfiguration = "";
    List<? extends HasMetadata> runs = new ArrayList<>();
    if (element instanceof PipelineRunNode) {
        runConfiguration = tkncli.getPipelineRunYAML(namespace, element.getName());
        String pipeline = YAMLHelper.getStringValueFromYAML(runConfiguration, new String[] { "metadata", "labels", "tekton.dev/pipeline" });
        configuration = tkncli.getPipelineYAML(namespace, pipeline);
        runs = tkncli.getPipelineRuns(namespace, pipeline);
    } else if (element instanceof TaskRunNode) {
        runConfiguration = tkncli.getTaskRunYAML(namespace, element.getName());
        Pair<String, String> taskNameAndConfiguration = getTaskConfiguration(namespace, tkncli, runConfiguration);
        if (taskNameAndConfiguration == null) {
            throw new IOException("Error: Unable to retrieve task from this taskrun");
        }
        configuration = taskNameAndConfiguration.getSecond();
        runs = tkncli.getTaskRuns(namespace, taskNameAndConfiguration.getFirst());
    }
    StartResourceModel model = new StartResourceModel(configuration, resources, serviceAccounts, secrets, configMaps, persistentVolumeClaims, runs);
    model.adaptsToRun(runConfiguration);
    return model;
}
Also used : ArrayList(java.util.ArrayList) StartResourceModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.StartResourceModel) TaskRunNode(com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode) IOException(java.io.IOException) PipelineRunNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode) Pair(com.intellij.openapi.util.Pair)

Example 4 with TaskRunNode

use of com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode in project intellij-tekton by redhat-developer.

the class ShowDiagnosticDataAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
    ActionMessage telemetry = instance().action(NAME_PREFIX_DIAG + "show diagnostic data");
    ExecHelper.submit(() -> {
        ParentableNode element = getElement(selected);
        String namespace = element.getNamespace();
        boolean hasDataToShow = false;
        try {
            if (element instanceof PipelineRunNode) {
                telemetry.property(PROP_RESOURCE_KIND, Constants.KIND_PIPELINERUN);
                hasDataToShow = tkncli.getDiagnosticData(namespace, "tekton.dev/pipelineRun", element.getName());
            } else if (element instanceof TaskRunNode) {
                telemetry.property(PROP_RESOURCE_KIND, Constants.KIND_TASKRUN);
                hasDataToShow = tkncli.getDiagnosticData(namespace, "tekton.dev/taskRun", element.getName());
            }
            if (!hasDataToShow) {
                String message = "No data available for " + element.getName() + " in namespace " + namespace + ".";
                telemetry.result(anonymizeResource(element.getName(), namespace, message)).send();
                UIHelper.executeInUI(() -> Messages.showWarningDialog("No data available for " + element.getName() + " in namespace " + namespace + ".", "Diagnostic Data"));
            } else {
                telemetry.success().send();
            }
        } catch (IOException e) {
            telemetry.error(anonymizeResource(element.getName(), namespace, e.getMessage())).send();
            UIHelper.executeInUI(() -> Messages.showErrorDialog("Failed to retrieve data for " + element.getName() + " in namespace " + namespace + ". An error occurred while retrieving them.\n" + e.getLocalizedMessage(), "Error"));
            logger.warn("Error: " + e.getLocalizedMessage(), e);
            return;
        }
    });
}
Also used : ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) TaskRunNode(com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode) IOException(java.io.IOException) PipelineRunNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode)

Example 5 with TaskRunNode

use of com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode in project intellij-tekton by redhat-developer.

the class StartAction method refreshTreeNode.

private void refreshTreeNode(AnActionEvent anActionEvent, ParentableNode element) {
    ParentableNode nodeToRefresh = element;
    if (element instanceof PipelineRunNode || element instanceof TaskRunNode) {
        nodeToRefresh = (ParentableNode) element.getParent();
    }
    ((TektonTreeStructure) getTree(anActionEvent).getClientProperty(Constants.STRUCTURE_PROPERTY)).fireModified(nodeToRefresh);
}
Also used : ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) TektonTreeStructure(com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure) TaskRunNode(com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode) PipelineRunNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode)

Aggregations

PipelineRunNode (com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode)5 TaskRunNode (com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode)5 IOException (java.io.IOException)4 ParentableNode (com.redhat.devtools.intellij.tektoncd.tree.ParentableNode)3 ActionMessage (com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage)2 Notification (com.intellij.notification.Notification)1 Pair (com.intellij.openapi.util.Pair)1 Tkn (com.redhat.devtools.intellij.tektoncd.tkn.Tkn)1 ClusterTaskNode (com.redhat.devtools.intellij.tektoncd.tree.ClusterTaskNode)1 ClusterTriggerBindingNode (com.redhat.devtools.intellij.tektoncd.tree.ClusterTriggerBindingNode)1 ConditionNode (com.redhat.devtools.intellij.tektoncd.tree.ConditionNode)1 EventListenerNode (com.redhat.devtools.intellij.tektoncd.tree.EventListenerNode)1 PipelineNode (com.redhat.devtools.intellij.tektoncd.tree.PipelineNode)1 ResourceNode (com.redhat.devtools.intellij.tektoncd.tree.ResourceNode)1 TaskNode (com.redhat.devtools.intellij.tektoncd.tree.TaskNode)1 TektonTreeStructure (com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure)1 TriggerBindingNode (com.redhat.devtools.intellij.tektoncd.tree.TriggerBindingNode)1 TriggerTemplateNode (com.redhat.devtools.intellij.tektoncd.tree.TriggerTemplateNode)1 StartResourceModel (com.redhat.devtools.intellij.tektoncd.utils.model.actions.StartResourceModel)1 ArrayList (java.util.ArrayList)1