Search in sources :

Example 1 with PipelineNode

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

the class AddTriggerAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
    ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_CRUD + "add trigger");
    ParentableNode element = getElement(selected);
    String namespace = element.getNamespace();
    ExecHelper.submit(() -> {
        try {
            String triggerVersion = tkncli.getTektonTriggersApiVersion();
            Map<String, String> triggerBindingTemplates = SnippetHelper.getTriggerBindingTemplates(triggerVersion);
            AddTriggerModel model = createModel(element, namespace, tkncli);
            if (!model.isValid()) {
                UIHelper.executeInUI(() -> Messages.showErrorDialog(model.getErrorMessage(), "Error"));
                return;
            }
            String kind = (element instanceof PipelineNode) ? "Pipeline " : "Task ";
            telemetry.property(PROP_RESOURCE_KIND, kind);
            AddTriggerWizard addTriggerWizard = openTriggerBindingWizard(anActionEvent, element, triggerBindingTemplates, model, kind);
            if (!addTriggerWizard.isOK()) {
                telemetry.result(VALUE_ABORTED).send();
                return;
            }
            createNewVolumes(model.getWorkspaces(), tkncli);
            // take/create all triggerBindings
            Map<String, String> triggerBindingsSelected = model.getBindingsSelectedByUser();
            saveTriggerBindings(triggerBindingsSelected, namespace, tkncli);
            // get all params from bindings
            Set<String> paramsFromBindings = model.extractVariablesFromSelectedBindings();
            // interpolate the variables correctly $variable to $(tt.params.variable)
            normalizeVariablesInterpolation(model, paramsFromBindings);
            // create the triggerTemplate
            String randomString = Utils.getRandomString(6);
            String triggerTemplateName = element.getName() + "-template-" + randomString;
            ObjectNode run = createNode(element, model);
            String triggerApiVersion = tkncli.getTektonTriggersApiVersion();
            ObjectNode triggerTemplate = YAMLBuilder.createTriggerTemplate(triggerTemplateName, triggerApiVersion, new ArrayList<>(paramsFromBindings), Arrays.asList(run));
            saveResource(YAMLHelper.JSONToYAML(triggerTemplate), namespace, KIND_TRIGGERTEMPLATES, tkncli);
            notifySuccessOperation("TriggerTemplate " + triggerTemplateName);
            // create the eventListener
            String eventListenerName = element.getName() + "-listener-" + randomString;
            // TODO we are using the default pipeline serviceAccount but we should allow users to select the one they prefer
            ObjectNode eventListener = YAMLBuilder.createEventListener(eventListenerName, triggerApiVersion, "pipeline", triggerBindingsSelected.keySet().stream().map(binding -> binding.replace(" NEW", "")).collect(Collectors.toList()), triggerTemplateName);
            saveResource(YAMLHelper.JSONToYAML(eventListener), namespace, KIND_EVENTLISTENERS, tkncli);
            telemetry.result("bindings and resources created").send();
            notifySuccessOperation("EventListener " + eventListenerName);
            TreeHelper.refresh(getEventProject(anActionEvent), (ParentableNode) ((ParentableNode) element.getParent()).getParent());
        } catch (IOException e) {
            String errorMessage = "Failed to add a trigger to " + element.getName() + " in namespace " + namespace + "\n" + e.getLocalizedMessage();
            telemetry.error(anonymizeResource(element.getName(), namespace, errorMessage)).send();
            Notification notification = new Notification(NOTIFICATION_ID, "Error", errorMessage, NotificationType.ERROR);
            Notifications.Bus.notify(notification);
            logger.warn(errorMessage, e);
        }
    });
}
Also used : AddTriggerWizard(com.redhat.devtools.intellij.tektoncd.ui.wizard.addtrigger.AddTriggerWizard) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) AddTriggerModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel) IOException(java.io.IOException) PipelineNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineNode) Notification(com.intellij.notification.Notification)

Example 2 with PipelineNode

use of com.redhat.devtools.intellij.tektoncd.tree.PipelineNode 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 3 with PipelineNode

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

the class WatchNodes method setWatchByNode.

public void setWatchByNode(ParentableNode<?> element) {
    String namespace = element.getNamespace();
    String watchId = getWatchId(element);
    Watch watch = null;
    WatchNodes wn = null;
    // (e.g a taskRuns watcher, when a change happens, could update multiple nodes such as a single Task node and the TaskRuns node)
    if (this.watches.containsKey(watchId)) {
        wn = this.watches.get(watchId);
        if (wn.getNodes().stream().noneMatch(item -> item.getName().equalsIgnoreCase(element.getName()) && ((ParentableNode) item.getParent()).getName().equalsIgnoreCase(((ParentableNode) element.getParent()).getName()))) {
            wn.getNodes().add(element);
        }
        return;
    }
    Watcher watcher = getWatcher(watchId, element.getRoot().getProject());
    try {
        if (element instanceof PipelinesNode) {
            watch = tkn.watchPipelines(namespace, watcher);
        } else if (element instanceof PipelineNode) {
            // we are expanding a single pipeline node and we want it to refresh if its children (pipelineruns) change
            watch = tkn.watchPipelineRuns(namespace, watcher);
        } else if (element instanceof PipelineRunsNode) {
            watch = tkn.watchPipelineRuns(namespace, watcher);
        } else if (element instanceof PipelineRunNode) {
            // we are expanding a single pipelinerun node and we want it to refresh if its children (taskruns) change
            watch = tkn.watchTaskRuns(namespace, watcher);
        } else if (element instanceof ResourcesNode) {
            watch = tkn.watchPipelineResources(namespace, watcher);
        } else if (element instanceof TasksNode) {
            watch = tkn.watchTasks(namespace, watcher);
        } else if (element instanceof TaskNode) {
            // we are expanding a single task node and we want it to refresh if its children (taskruns) change
            watch = tkn.watchTaskRuns(namespace, watcher);
        } else if (element instanceof TaskRunsNode) {
            watch = tkn.watchTaskRuns(namespace, watcher);
        } else if (element instanceof ClusterTasksNode) {
            watch = tkn.watchClusterTasks(watcher);
        } else if (element instanceof ConditionsNode) {
            watch = tkn.watchConditions(namespace, watcher);
        } else if (element instanceof TriggerTemplatesNode) {
            watch = tkn.watchTriggerTemplates(namespace, watcher);
        } else if (element instanceof TriggerBindingsNode) {
            watch = tkn.watchTriggerBindings(namespace, watcher);
        } else if (element instanceof ClusterTriggerBindingsNode) {
            watch = tkn.watchClusterTriggerBindings(watcher);
        } else if (element instanceof EventListenersNode) {
            watch = tkn.watchEventListeners(namespace, watcher);
        }
        wn = new WatchNodes(watch, element);
    } catch (IOException e) {
        logger.warn("Error: " + e.getLocalizedMessage(), e);
    }
    if (wn != null) {
        watches.put(watchId, wn);
    }
}
Also used : PipelinesNode(com.redhat.devtools.intellij.tektoncd.tree.PipelinesNode) TaskNode(com.redhat.devtools.intellij.tektoncd.tree.TaskNode) ClusterTriggerBindingsNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTriggerBindingsNode) Watcher(io.fabric8.kubernetes.client.Watcher) IOException(java.io.IOException) PipelineNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineNode) ResourcesNode(com.redhat.devtools.intellij.tektoncd.tree.ResourcesNode) ClusterTriggerBindingsNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTriggerBindingsNode) TriggerBindingsNode(com.redhat.devtools.intellij.tektoncd.tree.TriggerBindingsNode) PipelineRunsNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineRunsNode) PipelineRunNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode) TasksNode(com.redhat.devtools.intellij.tektoncd.tree.TasksNode) ClusterTasksNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTasksNode) EventListenersNode(com.redhat.devtools.intellij.tektoncd.tree.EventListenersNode) Watch(io.fabric8.kubernetes.client.Watch) TriggerTemplatesNode(com.redhat.devtools.intellij.tektoncd.tree.TriggerTemplatesNode) ConditionsNode(com.redhat.devtools.intellij.tektoncd.tree.ConditionsNode) TaskRunsNode(com.redhat.devtools.intellij.tektoncd.tree.TaskRunsNode) ClusterTasksNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTasksNode)

Example 4 with PipelineNode

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

the class StartAction method canBeStarted.

protected boolean canBeStarted(Project project, ParentableNode element, StartResourceModel model) {
    boolean hasNoInputs = model.getParams().isEmpty() && model.getInputResources().isEmpty() && model.getOutputResources().isEmpty() && model.getWorkspaces().isEmpty();
    boolean showWizard = SettingsState.getInstance().showStartWizardWithNoInputs || !hasNoInputs;
    if (showWizard) {
        StartWizard startWizard = UIHelper.executeInUI(() -> {
            String titleDialog = ((element instanceof PipelineNode) ? "Pipeline " : "Task ") + element.getName();
            StartWizard wizard = new StartWizard(titleDialog, element, project, model);
            wizard.show();
            return wizard;
        });
        if (startWizard != null && !startWizard.isOK()) {
            telemetry.result(VALUE_ABORTED).send();
            return false;
        }
    }
    return true;
}
Also used : StartWizard(com.redhat.devtools.intellij.tektoncd.ui.wizard.StartWizard) PipelineNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineNode)

Aggregations

PipelineNode (com.redhat.devtools.intellij.tektoncd.tree.PipelineNode)4 IOException (java.io.IOException)3 PipelineRunNode (com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode)2 TaskNode (com.redhat.devtools.intellij.tektoncd.tree.TaskNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Notification (com.intellij.notification.Notification)1 Tkn (com.redhat.devtools.intellij.tektoncd.tkn.Tkn)1 ClusterTaskNode (com.redhat.devtools.intellij.tektoncd.tree.ClusterTaskNode)1 ClusterTasksNode (com.redhat.devtools.intellij.tektoncd.tree.ClusterTasksNode)1 ClusterTriggerBindingNode (com.redhat.devtools.intellij.tektoncd.tree.ClusterTriggerBindingNode)1 ClusterTriggerBindingsNode (com.redhat.devtools.intellij.tektoncd.tree.ClusterTriggerBindingsNode)1 ConditionNode (com.redhat.devtools.intellij.tektoncd.tree.ConditionNode)1 ConditionsNode (com.redhat.devtools.intellij.tektoncd.tree.ConditionsNode)1 EventListenerNode (com.redhat.devtools.intellij.tektoncd.tree.EventListenerNode)1 EventListenersNode (com.redhat.devtools.intellij.tektoncd.tree.EventListenersNode)1 ParentableNode (com.redhat.devtools.intellij.tektoncd.tree.ParentableNode)1 PipelineRunsNode (com.redhat.devtools.intellij.tektoncd.tree.PipelineRunsNode)1 PipelinesNode (com.redhat.devtools.intellij.tektoncd.tree.PipelinesNode)1 ResourceNode (com.redhat.devtools.intellij.tektoncd.tree.ResourceNode)1 ResourcesNode (com.redhat.devtools.intellij.tektoncd.tree.ResourcesNode)1