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();
}
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();
}
});
}
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;
}
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();
}
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;
}
Aggregations