Search in sources :

Example 1 with PipelineRunConfigurationModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.runs.PipelineRunConfigurationModel in project intellij-tekton by redhat-developer.

the class StartResourceModel method adaptsToRun.

public void adaptsToRun(String configuration) {
    ConfigurationModel model = ConfigurationModelFactory.getModel(configuration);
    if (!(model instanceof RunConfigurationModel))
        return;
    // update params/input resources
    this.resource.getParams().forEach(input -> {
        // for each input, update its defaultValue/Value with the value taken from the *run model
        if (((RunConfigurationModel) model).getParameters().containsKey(input.name())) {
            String value = ((RunConfigurationModel) model).getParameters().get(input.name());
            input.setDefaultValue(value);
        }
    });
    this.resource.getInputResources().forEach(input -> {
        // for each input, update its defaultValue/Value with the value taken from the *run model
        String value = null;
        if (model instanceof PipelineRunConfigurationModel) {
            if (((PipelineRunConfigurationModel) model).getResources().containsKey(input.name())) {
                value = ((PipelineRunConfigurationModel) model).getResources().get(input.name());
            }
        } else {
            if (((TaskRunConfigurationModel) model).getInputResources().containsKey(input.name())) {
                value = ((TaskRunConfigurationModel) model).getInputResources().get(input.name());
            }
        }
        if (value != null) {
            input.setValue(value);
        }
    });
    // update output resource if its a taskrun
    if (model instanceof TaskRunConfigurationModel) {
        this.resource.getOutputResources().stream().forEach(output -> {
            if (((TaskRunConfigurationModel) model).getOutputResources().containsKey(output.name())) {
                output.setValue(((TaskRunConfigurationModel) model).getOutputResources().get(output.name()));
            }
        });
    }
    // update workspaces
    this.workspaces.keySet().forEach(workspaceName -> {
        if (((RunConfigurationModel) model).getWorkspacesValues().containsKey(workspaceName)) {
            this.workspaces.put(workspaceName, ((RunConfigurationModel) model).getWorkspacesValues().get(workspaceName));
        }
    });
    // update serviceAccount/taskServiceAccount
    String sa = ((RunConfigurationModel) model).getServiceAccountName();
    if (sa != null) {
        this.globalServiceAccount = sa;
    }
    this.taskServiceAccountNames.keySet().forEach(task -> {
        if (((RunConfigurationModel) model).getTaskServiceAccountNames().containsKey(task)) {
            this.taskServiceAccountNames.put(task, ((RunConfigurationModel) model).getTaskServiceAccountNames().get(task));
        }
    });
}
Also used : PipelineRunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.runs.PipelineRunConfigurationModel) ConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel) TaskRunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.runs.TaskRunConfigurationModel) PipelineRunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.runs.PipelineRunConfigurationModel) RunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.RunConfigurationModel) TaskRunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.runs.TaskRunConfigurationModel) PipelineRunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.runs.PipelineRunConfigurationModel) RunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.RunConfigurationModel) TaskRunConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.runs.TaskRunConfigurationModel)

Aggregations

ConfigurationModel (com.redhat.devtools.intellij.tektoncd.utils.model.ConfigurationModel)1 RunConfigurationModel (com.redhat.devtools.intellij.tektoncd.utils.model.RunConfigurationModel)1 PipelineRunConfigurationModel (com.redhat.devtools.intellij.tektoncd.utils.model.runs.PipelineRunConfigurationModel)1 TaskRunConfigurationModel (com.redhat.devtools.intellij.tektoncd.utils.model.runs.TaskRunConfigurationModel)1