use of com.redhat.devtools.intellij.tektoncd.utils.model.RunConfigurationModel 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));
}
});
}
Aggregations