Search in sources :

Example 1 with Input

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;
}
Also used : Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with Input

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();
}
Also used : ExecHelper(com.redhat.devtools.intellij.common.utils.ExecHelper) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 3 with Input

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;
}
Also used : Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 4 with Input

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());
        }
    }
}
Also used : Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) Output(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Output) Resource(com.redhat.devtools.intellij.tektoncd.tkn.Resource) List(java.util.List)

Example 5 with Input

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);
}
Also used : Arrays(java.util.Arrays) Watcher(io.fabric8.kubernetes.client.Watcher) Assert.assertTrue(org.junit.Assert.assertTrue) Watch(io.fabric8.kubernetes.client.Watch) IOException(java.io.IOException) HashMap(java.util.HashMap) Test(org.junit.Test) TestUtils(com.redhat.devtools.intellij.tektoncd.TestUtils) TaskRun(io.fabric8.tekton.pipeline.v1beta1.TaskRun) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) WatcherException(io.fabric8.kubernetes.client.WatcherException) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) Optional(java.util.Optional) TektonClient(io.fabric8.tekton.client.TektonClient) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) HashMap(java.util.HashMap) TektonClient(io.fabric8.tekton.client.TektonClient) Watch(io.fabric8.kubernetes.client.Watch) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Input (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input)13 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 ExecHelper (com.redhat.devtools.intellij.common.utils.ExecHelper)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 Workspace (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)3 List (java.util.List)3 Map (java.util.Map)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 TestUtils (com.redhat.devtools.intellij.tektoncd.TestUtils)2 Resource (com.redhat.devtools.intellij.tektoncd.tkn.Resource)2 BORDER_LABEL_NAME (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.BORDER_LABEL_NAME)2 ROW_DIMENSION (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION)2 TIMES_PLAIN_14 (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_14)2 ActionToRunModel (com.redhat.devtools.intellij.tektoncd.utils.model.actions.ActionToRunModel)2 Watch (io.fabric8.kubernetes.client.Watch)2 Watcher (io.fabric8.kubernetes.client.Watcher)2 WatcherException (io.fabric8.kubernetes.client.WatcherException)2 TektonClient (io.fabric8.tekton.client.TektonClient)2