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