Search in sources :

Example 1 with StartResourceModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.actions.StartResourceModel in project intellij-tekton by redhat-developer.

the class StartAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
    this.telemetry = createTelemetry();
    ParentableNode element = getElement(selected);
    String namespace = element.getNamespace();
    ExecHelper.submit(() -> {
        StartResourceModel model = createModel(tkncli, element, namespace);
        if (model == null)
            return;
        telemetry.property(PROP_RESOURCE_KIND, model.getKind());
        if (!model.isValid()) {
            telemetry.error(model.getErrorMessage()).send();
            UIHelper.executeInUI(() -> Messages.showErrorDialog(model.getErrorMessage(), "Error"));
            return;
        }
        Project project = getEventProject(anActionEvent);
        if (!canBeStarted(project, element, model)) {
            return;
        }
        try {
            createNewVolumes(model.getWorkspaces(), tkncli);
            String runName = doStart(tkncli, namespace, model);
            FollowLogsAction.run(namespace, runName, element.getClass(), tkncli);
            refreshTreeNode(anActionEvent, element);
            telemetry.send();
        } catch (IOException e) {
            String errorMessage = model.getName() + " in namespace " + namespace + " failed to start\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("Error: " + e.getLocalizedMessage(), e);
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) StartResourceModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.StartResourceModel) IOException(java.io.IOException) Notification(com.intellij.notification.Notification)

Example 2 with StartResourceModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.actions.StartResourceModel in project intellij-tekton by redhat-developer.

the class StartWizard method getOptionsPanel.

private JPanel getOptionsPanel(List<String> optionsToDisplay, ActionToRunModel model, ParentableNode element) {
    JPanel innerOptionsPanel = new JPanel(new GridBagLayout());
    innerOptionsPanel.setBackground(backgroundTheme);
    innerOptionsPanel.setBorder(MARGIN_10);
    int row = 0;
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.anchor = GridBagConstraints.WEST;
    // set prefix for runs
    if (optionsToDisplay.contains(PREFIX_NAME_RUN)) {
        JLabel lblRunPrefixName = new JLabel("Prefix for the *Run name: ");
        lblRunPrefixName.setFont(TIMES_PLAIN_14);
        JLabel lblRunPrefixName_Help = new JLabel();
        lblRunPrefixName_Help.setIcon(AllIcons.General.Information);
        lblRunPrefixName_Help.setToolTipText("Specify a prefix for the *Run name (must be lowercase alphanumeric characters)");
        txtRunPrefixName = new JTextField();
        txtRunPrefixName.setPreferredSize(ROW_DIMENSION);
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = row;
        innerOptionsPanel.add(lblRunPrefixName, gridBagConstraints);
        gridBagConstraints.gridx = 1;
        innerOptionsPanel.add(txtRunPrefixName, gridBagConstraints);
        gridBagConstraints.gridx = 2;
        innerOptionsPanel.add(lblRunPrefixName_Help, gridBagConstraints);
        row++;
    }
    // import data from *run
    if (optionsToDisplay.contains(IMPORT_DATA_FROM_RUN)) {
        JCheckBox chkImportRunData = new JCheckBox("Import data from run");
        chkImportRunData.setBackground(backgroundTheme);
        JLabel chkImportRunData_Help = new JLabel();
        chkImportRunData_Help.setIcon(AllIcons.General.Information);
        chkImportRunData_Help.setToolTipText("Fill all wizard inputs with the values taken from an old *run");
        JComboBox cmbPickRunToImportData = new ComboBox();
        cmbPickRunToImportData.setEnabled(false);
        cmbPickRunToImportData.setPreferredSize(ROW_DIMENSION);
        chkImportRunData.addItemListener(itemEvent -> {
            if (chkImportRunData.isSelected()) {
                cmbPickRunToImportData.setEnabled(true);
            } else {
                cmbPickRunToImportData.setEnabled(false);
            }
        });
        cmbPickRunToImportData.addItem("Please choose");
        ((StartResourceModel) model).getRuns().forEach(run -> cmbPickRunToImportData.addItem(run.getMetadata().getName()));
        cmbPickRunToImportData.addItemListener(itemEvent -> {
            // when combo box value change
            if (itemEvent.getStateChange() == 1) {
                if (itemEvent.getItem().toString().equals("Please choose"))
                    return;
                Tkn tkncli = element.getRoot().getTkn();
                String configuration = "";
                String kind = model.getKind();
                try {
                    if (kind.equalsIgnoreCase(KIND_PIPELINE)) {
                        configuration = tkncli.getPipelineRunYAML(element.getNamespace(), itemEvent.getItem().toString());
                    } else if (kind.equalsIgnoreCase(KIND_TASK) || kind.equalsIgnoreCase(KIND_CLUSTERTASK)) {
                        configuration = tkncli.getTaskRunYAML(element.getNamespace(), itemEvent.getItem().toString());
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (!configuration.isEmpty()) {
                    ((StartResourceModel) model).adaptsToRun(configuration);
                    refreshSteps();
                    updatePreview(model);
                }
            }
        });
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = row;
        innerOptionsPanel.add(chkImportRunData, gridBagConstraints);
        gridBagConstraints.gridx = 1;
        innerOptionsPanel.add(cmbPickRunToImportData, gridBagConstraints);
        gridBagConstraints.gridx = 2;
        innerOptionsPanel.add(chkImportRunData_Help, gridBagConstraints);
        row++;
    }
    return innerOptionsPanel;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) JComboBox(javax.swing.JComboBox) ComboBox(com.intellij.openapi.ui.ComboBox) JLabel(javax.swing.JLabel) IOException(java.io.IOException) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) StartResourceModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.StartResourceModel)

Example 3 with StartResourceModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.actions.StartResourceModel 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 StartResourceModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.actions.StartResourceModel in project intellij-tekton by redhat-developer.

the class StartAction method createModel.

private StartResourceModel createModel(Tkn tkncli, ParentableNode element, String namespace) {
    StartResourceModel model = null;
    try {
        List<Resource> resources = tkncli.getResources(namespace);
        List<String> serviceAccounts = tkncli.getServiceAccounts(namespace);
        List<String> secrets = tkncli.getSecrets(namespace);
        List<String> configMaps = tkncli.getConfigMaps(namespace);
        List<String> persistentVolumeClaims = tkncli.getPersistentVolumeClaim(namespace);
        model = createModel(element, namespace, tkncli, resources, serviceAccounts, secrets, configMaps, persistentVolumeClaims);
    } catch (IOException e) {
        String errorMessage = element.getName() + " in namespace " + namespace + " failed to start. An error occurred while retrieving information.\n" + e.getLocalizedMessage();
        UIHelper.executeInUI(() -> {
            telemetry.error(anonymizeResource(element.getName(), namespace, errorMessage)).send();
            Messages.showErrorDialog(errorMessage, "Error");
        });
        logger.warn("Error: " + errorMessage, e);
    }
    return model;
}
Also used : StartResourceModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.StartResourceModel) Resource(com.redhat.devtools.intellij.tektoncd.tkn.Resource) AnonymizeUtils.anonymizeResource(com.redhat.devtools.intellij.telemetry.core.util.AnonymizeUtils.anonymizeResource) IOException(java.io.IOException)

Aggregations

StartResourceModel (com.redhat.devtools.intellij.tektoncd.utils.model.actions.StartResourceModel)4 IOException (java.io.IOException)4 Notification (com.intellij.notification.Notification)1 Project (com.intellij.openapi.project.Project)1 ComboBox (com.intellij.openapi.ui.ComboBox)1 Pair (com.intellij.openapi.util.Pair)1 Resource (com.redhat.devtools.intellij.tektoncd.tkn.Resource)1 Tkn (com.redhat.devtools.intellij.tektoncd.tkn.Tkn)1 ParentableNode (com.redhat.devtools.intellij.tektoncd.tree.ParentableNode)1 PipelineRunNode (com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode)1 TaskRunNode (com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode)1 AnonymizeUtils.anonymizeResource (com.redhat.devtools.intellij.telemetry.core.util.AnonymizeUtils.anonymizeResource)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 ArrayList (java.util.ArrayList)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JTextField (javax.swing.JTextField)1