use of com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel 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.utils.model.resources.TaskConfigurationModel in project intellij-tekton by redhat-developer.
the class VariableReferencesInspector method checkFile.
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
ConfigurationModel model = getTektonModelFromFile(file);
if (model == null) {
return ProblemDescriptor.EMPTY_ARRAY;
}
List<PsiElement> unusedPsiElements = new ArrayList<>();
if (model instanceof PipelineConfigurationModel) {
unusedPsiElements = highlightInPipeline(file, (PipelineConfigurationModel) model);
} else if (model instanceof TaskConfigurationModel) {
unusedPsiElements = highlightInTask(file, (TaskConfigurationModel) model);
}
return unusedPsiElements.stream().map(item -> manager.createProblemDescriptor(item, item, "Variable " + StringHelper.getUnquotedValueFromPsi(item.getContext()) + " is never used", ProblemHighlightType.WEAK_WARNING, isOnTheFly, LocalQuickFix.EMPTY_ARRAY)).toArray(ProblemDescriptor[]::new);
}
use of com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel in project intellij-tekton by redhat-developer.
the class CreateTaskRunTemplateAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_CRUD + "create task run");
ParentableNode element = getElement(selected);
String namespace = element.getNamespace();
ExecHelper.submit(() -> {
Notification notification;
TaskConfigurationModel model;
try {
model = getModel(element, namespace, tkncli);
} catch (IOException e) {
String errorMessage = "Failed to create TaskRun templace from " + element.getName() + " in namespace " + namespace + "An error occurred while retrieving information.\n" + e.getLocalizedMessage();
telemetry.error(anonymizeResource(element.getName(), namespace, errorMessage)).send();
UIHelper.executeInUI(() -> {
Messages.showErrorDialog(errorMessage, "Error");
});
logger.warn("Error: " + e.getLocalizedMessage(), e);
return;
}
if (!model.isValid()) {
String errorMessage = "Failed to create a TaskRun templace from " + element.getName() + " in namespace " + namespace + ". The task is not valid.";
telemetry.error(anonymizeResource(element.getName(), namespace, errorMessage)).send();
UIHelper.executeInUI(() -> Messages.showErrorDialog(errorMessage, "Error"));
return;
}
try {
String contentTask = new YAMLMapper().writeValueAsString(YAMLBuilder.createTaskRun(model));
openEditor(anActionEvent.getProject(), namespace, telemetry, model, contentTask);
} catch (IOException e) {
String errorMessage = "Failed to create TaskRun templace from" + element.getName() + " in namespace " + namespace + " \n" + e.getLocalizedMessage();
telemetry.error(anonymizeResource(element.getName(), namespace, errorMessage)).send();
notification = new Notification(NOTIFICATION_ID, "Error", errorMessage, NotificationType.ERROR);
Notifications.Bus.notify(notification);
logger.warn(errorMessage, e);
}
});
}
use of com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel in project intellij-tekton by redhat-developer.
the class YAMLBuilderTest method checkTaskRunCreatedWithTaskConfigurationModelWithWorkspace.
@Test
public void checkTaskRunCreatedWithTaskConfigurationModelWithWorkspace() throws IOException {
String content = load("task10.yaml");
TaskConfigurationModel model = new TaskConfigurationModel(content);
ObjectNode taskRunNode = YAMLBuilder.createTaskRun(model);
assertEquals(taskRunNode.get("apiVersion").asText(), "tekton.dev/v1beta1");
assertEquals(taskRunNode.get("kind").asText(), "TaskRun");
assertEquals(taskRunNode.get("metadata").get("generateName").asText(), "foo-");
assertEquals(taskRunNode.get("spec").get("taskRef").get("name").asText(), "foo");
assertTrue(taskRunNode.get("spec").has("serviceAccountName"));
assertEquals(taskRunNode.get("spec").get("serviceAccountName").asText(), "");
assertFalse(taskRunNode.get("spec").has("serviceAccountNames"));
assertFalse(taskRunNode.get("spec").has("params"));
assertFalse(taskRunNode.get("spec").has("resources"));
assertTrue(taskRunNode.get("spec").has("workspaces"));
assertEquals(taskRunNode.get("spec").get("workspaces").get(0).get("name").asText(), "write-allowed");
assertEquals(taskRunNode.get("spec").get("workspaces").get(1).get("name").asText(), "write-disallowed");
assertTrue(taskRunNode.get("spec").get("workspaces").get(0).has("emptyDir"));
assertTrue(taskRunNode.get("spec").get("workspaces").get(1).has("emptyDir"));
}
use of com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel in project intellij-tekton by redhat-developer.
the class TaskConfigurationModelTest method checkTaskModelWithWorkspaces.
@Test
public void checkTaskModelWithWorkspaces() throws IOException {
String configuration = load("task10.yaml");
TaskConfigurationModel model = (TaskConfigurationModel) ConfigurationModelFactory.getModel(configuration);
assertEquals(model.getName(), "foo");
assertEquals(model.getNamespace(), "tekton");
assertEquals(model.getKind(), "Task");
assertTrue(model.getParams().isEmpty());
assertTrue(model.getInputResources().isEmpty());
assertTrue(model.getOutputResources().isEmpty());
assertTrue(model.getWorkspaces().size() == 2);
assertEquals(model.getWorkspaces().get(0).getName(), "write-allowed");
assertEquals(model.getWorkspaces().get(1).getName(), "write-disallowed");
}
Aggregations