Search in sources :

Example 1 with Workspace

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace in project intellij-tekton by redhat-developer.

the class WorkspacesStep method updateWorkspaceModel.

private void updateWorkspaceModel(JPanel panel, String workspaceName, Workspace.Kind kind, String resource) {
    Workspace workspace = model.getWorkspaces().get(workspaceName);
    boolean isOptional = workspace.isOptional();
    if (kind == PVC) {
        JComboBox cmbWorkspaceTypeValues = (JComboBox) Arrays.stream(panel.getComponents()).filter(component -> "cmbWorkspaceTypeValues".equals(component.getName())).findFirst().get();
        String valueSelected = cmbWorkspaceTypeValues.getSelectedItem().toString();
        if (valueSelected.equals(NEW_PVC_TEXT)) {
            JPanel newPVCNamePanel = (JPanel) Arrays.stream(panel.getComponents()).filter(component -> "newPVCNamePanel".equals(component.getName())).findFirst().get();
            JTextField newPVCNameTextField = (JTextField) Arrays.stream(newPVCNamePanel.getComponents()).filter(component -> "txtNameNewPVC".equals(component.getName())).findFirst().get();
            String nameNewPVC = newPVCNameTextField.getText();
            newPVCNameTextField.setBorder(nameNewPVC.isEmpty() ? RED_BORDER_SHOW_ERROR : NO_BORDER);
            workspace = saveNewVolume(workspaceName, nameNewPVC, PVC, panel, isOptional);
        } else if (valueSelected.equals(NEW_VCT_TEXT)) {
            workspace = saveNewVolume(workspaceName, workspaceName + "-vct", PVC, panel, true, isOptional);
        } else {
            workspace = new Workspace(workspaceName, kind, resource);
        }
    } else if (resource.isEmpty() && !isOptional && kind != EMPTYDIR) {
        workspace = new Workspace(workspaceName, null, null, isOptional);
    } else {
        workspace = new Workspace(workspaceName, kind, resource, isOptional);
    }
    model.getWorkspaces().put(workspaceName, workspace);
    fireStateChanged();
}
Also used : Color(java.awt.Color) ActionToRunModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.ActionToRunModel) Arrays(java.util.Arrays) KIND_VCT(com.redhat.devtools.intellij.tektoncd.Constants.KIND_VCT) TIMES_PLAIN_14(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_14) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) MatteBorder(javax.swing.border.MatteBorder) NumberFormatter(javax.swing.text.NumberFormatter) Border(javax.swing.border.Border) RED_BORDER_SHOW_ERROR(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.RED_BORDER_SHOW_ERROR) ROW_DIMENSION(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION) ColorKey(com.intellij.openapi.editor.colors.ColorKey) Map(java.util.Map) TIMES_PLAIN_10(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_10) TIMES_PLAIN_12(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_12) JComboBox(javax.swing.JComboBox) BorderLayout(java.awt.BorderLayout) Font(java.awt.Font) BorderFactory(javax.swing.BorderFactory) BasicComboBoxRenderer(javax.swing.plaf.basic.BasicComboBoxRenderer) GridBagConstraints(java.awt.GridBagConstraints) Component(java.awt.Component) Dimension(java.awt.Dimension) List(java.util.List) EmptyBorder(javax.swing.border.EmptyBorder) PVC(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.PVC) NotNull(org.jetbrains.annotations.NotNull) GridBagLayout(java.awt.GridBagLayout) DocumentAdapter(com.intellij.ui.DocumentAdapter) CONFIGMAP(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.CONFIGMAP) JPanel(javax.swing.JPanel) NO_BORDER(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.NO_BORDER) JTextField(javax.swing.JTextField) SpinnerNumberModel(javax.swing.SpinnerNumberModel) SECRET(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.SECRET) HashMap(java.util.HashMap) ROW_DIMENSION_ERROR(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION_ERROR) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) DocumentEvent(javax.swing.event.DocumentEvent) MARGIN_TOP_35(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.MARGIN_TOP_35) BORDER_LABEL_NAME(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.BORDER_LABEL_NAME) ComboBox(com.intellij.openapi.ui.ComboBox) JComponent(javax.swing.JComponent) EMPTYDIR(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.EMPTYDIR) JFormattedTextField(javax.swing.JFormattedTextField) JSpinner(javax.swing.JSpinner) JList(javax.swing.JList) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) ListCellRenderer(javax.swing.ListCellRenderer) JLabel(javax.swing.JLabel) Pair(com.intellij.openapi.util.Pair) JPanel(javax.swing.JPanel) JComboBox(javax.swing.JComboBox) JTextField(javax.swing.JTextField) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)

Example 2 with Workspace

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace in project intellij-tekton by redhat-developer.

the class WorkspacesStep method addListeners.

private void addListeners(String workspace, JPanel parent, int row) {
    JComboBox cmbWorkspaceTypes = (JComboBox) Arrays.stream(parent.getComponents()).filter(component -> component.getName() != null && component.getName().equals("cmbWorkspaceTypes")).findFirst().get();
    JComboBox cmbWorkspaceTypeValues = (JComboBox) Arrays.stream(parent.getComponents()).filter(component -> component.getName() != null && component.getName().equals("cmbWorkspaceTypeValues")).findFirst().get();
    cmbWorkspaceTypes.addItemListener(itemEvent -> {
        if (itemEvent.getStateChange() == 1) {
            // when cmbWorkspaceTypes combo box value changes, a type (secret, emptyDir, pvcs ..) is chosen and cmbWorkspaceTypeValues combo box is filled with all existing resources of that kind
            hidePVCAndVCTComponents(parent);
            Workspace.Kind kindSelected = cmbWorkspaceTypes.getSelectedItem().equals("") ? null : (Workspace.Kind) cmbWorkspaceTypes.getSelectedItem();
            setCmbWorkspaceTypeValues(workspace, kindSelected, cmbWorkspaceTypeValues, row);
            String resource = getSelectedWorkspaceType(cmbWorkspaceTypeValues);
            updateWorkspaceModel(parent, workspace, kindSelected, resource);
            // reset error graphics if error occurred earlier
            if (isValid(workspace, cmbWorkspaceTypes)) {
                changeErrorTextVisibility(false);
                cmbWorkspaceTypes.setBorder(new JComboBox().getBorder());
            }
            fireStateChanged();
        }
    });
    cmbWorkspaceTypeValues.addItemListener(itemEvent -> {
        if (itemEvent.getStateChange() == 1) {
            changeErrorTextVisibility(false);
            // when wsCB combo box value changes, wsTypesCB combo box is filled with all possible options
            String itemSelected = itemEvent.getItem().toString();
            hidePVCAndVCTComponents(parent);
            if (itemSelected.equals(NEW_VCT_TEXT)) {
                changeNewVCTComponentsVisibility(parent, true);
                updateWorkspaceModel(parent, workspace, PVC, "");
            } else if (itemSelected.equals(NEW_PVC_TEXT)) {
                changeNewPVCComponentsVisibility(parent, true);
                updateWorkspaceModel(parent, workspace, PVC, "");
            } else {
                updateWorkspaceModel(parent, workspace, (Workspace.Kind) cmbWorkspaceTypes.getSelectedItem(), itemEvent.getItem().toString());
            }
            fireStateChanged();
        }
    });
}
Also used : Color(java.awt.Color) ActionToRunModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.ActionToRunModel) Arrays(java.util.Arrays) KIND_VCT(com.redhat.devtools.intellij.tektoncd.Constants.KIND_VCT) TIMES_PLAIN_14(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_14) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) MatteBorder(javax.swing.border.MatteBorder) NumberFormatter(javax.swing.text.NumberFormatter) Border(javax.swing.border.Border) RED_BORDER_SHOW_ERROR(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.RED_BORDER_SHOW_ERROR) ROW_DIMENSION(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION) ColorKey(com.intellij.openapi.editor.colors.ColorKey) Map(java.util.Map) TIMES_PLAIN_10(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_10) TIMES_PLAIN_12(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_12) JComboBox(javax.swing.JComboBox) BorderLayout(java.awt.BorderLayout) Font(java.awt.Font) BorderFactory(javax.swing.BorderFactory) BasicComboBoxRenderer(javax.swing.plaf.basic.BasicComboBoxRenderer) GridBagConstraints(java.awt.GridBagConstraints) Component(java.awt.Component) Dimension(java.awt.Dimension) List(java.util.List) EmptyBorder(javax.swing.border.EmptyBorder) PVC(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.PVC) NotNull(org.jetbrains.annotations.NotNull) GridBagLayout(java.awt.GridBagLayout) DocumentAdapter(com.intellij.ui.DocumentAdapter) CONFIGMAP(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.CONFIGMAP) JPanel(javax.swing.JPanel) NO_BORDER(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.NO_BORDER) JTextField(javax.swing.JTextField) SpinnerNumberModel(javax.swing.SpinnerNumberModel) SECRET(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.SECRET) HashMap(java.util.HashMap) ROW_DIMENSION_ERROR(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION_ERROR) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) DocumentEvent(javax.swing.event.DocumentEvent) MARGIN_TOP_35(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.MARGIN_TOP_35) BORDER_LABEL_NAME(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.BORDER_LABEL_NAME) ComboBox(com.intellij.openapi.ui.ComboBox) JComponent(javax.swing.JComponent) EMPTYDIR(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.EMPTYDIR) JFormattedTextField(javax.swing.JFormattedTextField) JSpinner(javax.swing.JSpinner) JList(javax.swing.JList) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) ListCellRenderer(javax.swing.ListCellRenderer) JLabel(javax.swing.JLabel) Pair(com.intellij.openapi.util.Pair) JComboBox(javax.swing.JComboBox) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)

Example 3 with Workspace

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace in project intellij-tekton by redhat-developer.

the class YAMLBuilder method createRunInternal.

public static ObjectNode createRunInternal(String kind, ConfigurationModel model, boolean toDebug) {
    ObjectNode rootNode = YAML_MAPPER.createObjectNode();
    rootNode.put("apiVersion", "tekton.dev/v1beta1");
    rootNode.put("kind", kind);
    ObjectNode metadataNode = YAML_MAPPER.createObjectNode();
    metadataNode.put("generateName", model.getName() + "-");
    rootNode.set("metadata", metadataNode);
    ObjectNode spec = YAML_MAPPER.createObjectNode();
    if (model instanceof ActionToRunModel) {
        ActionToRunModel actionModel = (ActionToRunModel) model;
        if (kind.equalsIgnoreCase(KIND_PIPELINERUN)) {
            spec = createPipelineRunSpec(actionModel);
        } else {
            spec = createTaskRunSpec(actionModel.getResource().getName(), actionModel.getParams(), actionModel.getInputResources(), actionModel.getOutputResources(), actionModel.getWorkspaces(), actionModel.getServiceAccount().isEmpty() ? null : actionModel.getServiceAccount(), toDebug);
        }
    } else if (model instanceof TaskConfigurationModel) {
        Map<String, Workspace> workspaces = new HashMap<>();
        ((TaskConfigurationModel) model).getWorkspaces().stream().forEach(workspace -> {
            workspace.setKind(Workspace.Kind.EMPTYDIR);
            workspaces.put(workspace.getName(), workspace);
        });
        spec = createTaskRunSpec(model.getName(), ((TaskConfigurationModel) model).getParams(), ((TaskConfigurationModel) model).getInputResources(), ((TaskConfigurationModel) model).getOutputResources(), workspaces, "", toDebug);
    }
    rootNode.set("spec", spec);
    return rootNode;
}
Also used : WRITE_DOC_START_MARKER(com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature.WRITE_DOC_START_MARKER) ActionToRunModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.ActionToRunModel) YAMLHelper(com.redhat.devtools.intellij.common.utils.YAMLHelper) KIND_VCT(com.redhat.devtools.intellij.tektoncd.Constants.KIND_VCT) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Output(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Output) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) HashMap(java.util.HashMap) KIND_PIPELINERUN(com.redhat.devtools.intellij.tektoncd.Constants.KIND_PIPELINERUN) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TaskConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel) List(java.util.List) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) KIND_PVC(com.redhat.devtools.intellij.tektoncd.Constants.KIND_PVC) Map(java.util.Map) Pair(com.intellij.openapi.util.Pair) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) JsonNode(com.fasterxml.jackson.databind.JsonNode) KIND_PIPELINE(com.redhat.devtools.intellij.tektoncd.Constants.KIND_PIPELINE) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TaskConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel) HashMap(java.util.HashMap) Map(java.util.Map) ActionToRunModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.ActionToRunModel)

Example 4 with Workspace

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace in project intellij-tekton by redhat-developer.

the class TknCliTest method checkRightArgsWhenStartingTaskWithWorkspaces.

@Test
public void checkRightArgsWhenStartingTaskWithWorkspaces() throws IOException {
    Map<String, Workspace> workspaces = new HashMap<>();
    workspaces.put("work1", new Workspace("work1", Workspace.Kind.PVC, "value1"));
    workspaces.put("work2", new Workspace("work2", Workspace.Kind.CONFIGMAP, "value2"));
    workspaces.put("work3", new Workspace("work3", Workspace.Kind.SECRET, "value3"));
    workspaces.put("work4", new Workspace("work4", Workspace.Kind.EMPTYDIR, null));
    MockedStatic<ExecHelper> exec = mockStatic(ExecHelper.class);
    exec.when(() -> ExecHelper.execute(anyString(), anyMap(), any())).thenReturn("");
    tkn.startTask("ns", "name", Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), "", workspaces, "");
    exec.verify(() -> ExecHelper.execute(anyString(), anyMap(), eq("task"), eq("start"), eq("name"), eq("-n"), eq("ns"), eq("-w"), eq("name=work2,config=value2"), eq("-w"), eq("name=work1,claimName=value1"), eq("-w"), eq("name=work4,emptyDir="), eq("-w"), eq("name=work3,secret=value3"), eq(FLAG_SKIP_OPTIONAL_WORKSPACES)));
    exec.close();
}
Also used : ExecHelper(com.redhat.devtools.intellij.common.utils.ExecHelper) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) Test(org.junit.Test)

Example 5 with Workspace

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace in project intellij-tekton by redhat-developer.

the class YAMLBuilder method createWorkspaceNode.

private static ArrayNode createWorkspaceNode(Map<String, Workspace> workspaces) {
    ArrayNode workspacesNode = YAML_MAPPER.createArrayNode();
    for (Workspace workspace : workspaces.values()) {
        if (workspace.getKind() != null) {
            ObjectNode workspaceNode = createWorkspaceResourceNode(workspace);
            // TODO need to add subpath and items
            workspacesNode.add(workspaceNode);
        }
    }
    return workspacesNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)

Aggregations

Workspace (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)19 HashMap (java.util.HashMap)11 Test (org.junit.Test)7 ExecHelper (com.redhat.devtools.intellij.common.utils.ExecHelper)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 Pair (com.intellij.openapi.util.Pair)4 DocumentAdapter (com.intellij.ui.DocumentAdapter)4 KIND_VCT (com.redhat.devtools.intellij.tektoncd.Constants.KIND_VCT)4 GridBagConstraints (java.awt.GridBagConstraints)4 GridBagLayout (java.awt.GridBagLayout)4 JComboBox (javax.swing.JComboBox)4 Strings (com.google.common.base.Strings)3 ColorKey (com.intellij.openapi.editor.colors.ColorKey)3 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)3 ComboBox (com.intellij.openapi.ui.ComboBox)3 Input (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input)3 CONFIGMAP (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.CONFIGMAP)3