use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input in project intellij-tekton by redhat-developer.
the class YAMLBuilder method createParamsNodeFromInput.
private static ArrayNode createParamsNodeFromInput(List<Input> params) {
ArrayNode paramsNode = YAML_MAPPER.createArrayNode();
ObjectNode inputNode;
for (Input param : params) {
inputNode = YAML_MAPPER.createObjectNode();
inputNode.put("name", param.name());
String value = param.value() == null ? param.defaultValue().orElse("") : param.value();
if (param.type().equals("array")) {
ArrayNode paramValuesNode = YAML_MAPPER.valueToTree(value.split(","));
inputNode.set("value", paramValuesNode);
} else {
inputNode.put("value", value);
}
paramsNode.add(inputNode);
}
return paramsNode;
}
use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input in project intellij-tekton by redhat-developer.
the class TknCliTest method checkRightArgsWhenStartingPipelineWithParameters.
/* ////////////////////////////////////////////////////////////
* START
* ////////////////////////////////////////////////////////////
*/
@Test
public void checkRightArgsWhenStartingPipelineWithParameters() throws IOException {
Map<String, Input> params = new HashMap<>();
params.put("param1", new Input("param1", "string", Input.Kind.PARAMETER, "value1", Optional.empty(), Optional.empty()));
params.put("param2", new Input("param2", "string", Input.Kind.PARAMETER, "value2", Optional.empty(), Optional.empty()));
MockedStatic<ExecHelper> exec = mockStatic(ExecHelper.class);
exec.when(() -> ExecHelper.execute(anyString(), anyMap(), any())).thenReturn("");
tkn.startPipeline("ns", "name", params, Collections.emptyMap(), "", Collections.emptyMap(), Collections.emptyMap(), "");
exec.verify(() -> ExecHelper.execute(anyString(), anyMap(), eq("pipeline"), eq("start"), eq("name"), eq("-n"), eq("ns"), eq("-p"), eq("param1=value1"), eq("-p"), eq("param2=value2"), eq(FLAG_SKIP_OPTIONAL_WORKSPACES)));
exec.close();
}
use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input in project intellij-tekton by redhat-developer.
the class YAMLBuilder method createInputResourcesNode.
private static ArrayNode createInputResourcesNode(List<Input> inputResources) {
ArrayNode resourcesNode = YAML_MAPPER.createArrayNode();
ObjectNode inputNode;
for (Input input : inputResources) {
inputNode = YAML_MAPPER.createObjectNode();
inputNode.put("name", input.name());
// resourceRef node
ObjectNode resourceRefNode = YAML_MAPPER.createObjectNode();
resourceRefNode.put("name", input.value() == null ? "Resource has not yet been inserted" : input.value());
inputNode.set("resourceRef", resourceRefNode);
resourcesNode.add(inputNode);
}
return resourcesNode;
}
use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input in project intellij-tekton by redhat-developer.
the class ActionToRunModel method setDefaultValueResources.
private void setDefaultValueResources() {
if (this.pipelineResources == null || this.pipelineResources.isEmpty()) {
if (!this.getInputResources().isEmpty() || !this.getOutputResources().isEmpty()) {
errorMessage += " * The " + this.kind + " requires resources to be started but no resources were found in the cluster.\n";
isValid = false;
}
}
// set the first resource for a specific type (git, image, ...) as the default value for input/output
Map<String, List<Resource>> resourceGroupedByType = pipelineResources.stream().collect(Collectors.groupingBy(Resource::type));
if (!this.resource.getInputResources().isEmpty()) {
for (Input input : this.resource.getInputResources()) {
List<Resource> resourcesByInputType = resourceGroupedByType.get(input.type());
if (resourcesByInputType == null) {
errorMessage += " * The input " + input.name() + " requires a resource of type " + input.type() + " but no resource of that type was found in the cluster.\n";
isValid = false;
continue;
}
input.setValue(resourcesByInputType.get(0).name());
}
}
if (!this.resource.getOutputResources().isEmpty()) {
for (Output output : this.resource.getOutputResources()) {
List<Resource> resourcesByOutputType = resourceGroupedByType.get(output.type());
if (resourcesByOutputType == null) {
errorMessage += " * The output " + output.name() + " requires a resource of type " + output.type() + " but no resource of that type was found in the cluster.\n";
isValid = false;
continue;
}
output.setValue(resourcesByOutputType.get(0).name());
}
}
}
use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input in project intellij-tekton by redhat-developer.
the class TknCliTaskTest method verifyStartTaskCreateRuns.
@Test
public void verifyStartTaskCreateRuns() throws IOException, InterruptedException {
String TASK_NAME = "add-task-start-test";
String taskConfig = TestUtils.load("start/add-task.yaml").replace("add-task", TASK_NAME);
TestUtils.saveResource(tkn, taskConfig, NAMESPACE, "tasks");
// verify task has been created
List<String> tasks = tkn.getTasks(NAMESPACE).stream().map(task -> task.getMetadata().getName()).collect(Collectors.toList());
assertTrue(tasks.contains(TASK_NAME));
// start task and verify taskrun has been created
Map<String, Input> params = new HashMap<>();
params.put("first", new Input("name", "string", Input.Kind.PARAMETER, "value", Optional.empty(), Optional.empty()));
params.put("second", new Input("name2", "string", Input.Kind.PARAMETER, "value2", Optional.empty(), Optional.empty()));
tkn.startTask(NAMESPACE, TASK_NAME, params, Collections.emptyMap(), Collections.emptyMap(), "", Collections.emptyMap(), "");
final String[] nameTaskRun = { "" };
Watch watch = tkn.getClient(TektonClient.class).v1beta1().taskRuns().inNamespace(NAMESPACE).withLabel("tekton.dev/task", TASK_NAME).watch(createWatcher((resource) -> {
nameTaskRun[0] = resource.getMetadata().getName();
}));
stopAndWaitOnConditionOrTimeout(watch, () -> nameTaskRun[0].isEmpty());
assertFalse(nameTaskRun[0].isEmpty());
try {
// taskrun may have already finished its execution
tkn.cancelTaskRun(NAMESPACE, nameTaskRun[0]);
} catch (IOException ignored) {
}
// clean up
tkn.deleteTasks(NAMESPACE, Arrays.asList(TASK_NAME), true);
}
Aggregations