Monitor With Data Storage + Datas
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
||||
)
|
||||
|
||||
type Parameter struct {
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Value string `yaml:"value,omitempty"`
|
||||
@@ -12,9 +19,28 @@ type Container struct {
|
||||
VolumeMounts []VolumeMount `yaml:"volumeMounts,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Container) AddVolumeMount(volumeMount VolumeMount, volumes []VolumeMount) []VolumeMount {
|
||||
for _, vm := range c.VolumeMounts {
|
||||
if vm.Name == volumeMount.Name {
|
||||
return volumes
|
||||
}
|
||||
}
|
||||
c.VolumeMounts = append(c.VolumeMounts, volumeMount)
|
||||
for _, vm := range c.VolumeMounts {
|
||||
for _, v := range volumes {
|
||||
if vm.Name == v.Name {
|
||||
return volumes
|
||||
}
|
||||
}
|
||||
}
|
||||
volumes = append(volumes, volumeMount)
|
||||
return volumes
|
||||
}
|
||||
|
||||
type VolumeMount struct {
|
||||
Name string `yaml:"name"`
|
||||
MountPath string `yaml:"mountPath"`
|
||||
Name string `yaml:"name"`
|
||||
MountPath string `yaml:"mountPath"`
|
||||
Storage *storage.StorageResource `yaml:"-"`
|
||||
}
|
||||
|
||||
type Task struct {
|
||||
@@ -39,8 +65,47 @@ type Template struct {
|
||||
Inputs struct {
|
||||
Parameters []Parameter `yaml:"parameters"`
|
||||
} `yaml:"inputs,omitempty"`
|
||||
Container Container `yaml:"container,omitempty"`
|
||||
Dag Dag `yaml:"dag,omitempty"`
|
||||
Container Container `yaml:"container,omitempty"`
|
||||
Dag *Dag `yaml:"dag,omitempty"`
|
||||
Metadata TemplateMetadata `yaml:"metadata,omitempty"`
|
||||
Resource ServiceResource `yaml:"resource,omitempty"`
|
||||
Resource ServiceResource `yaml:"resource,omitempty"`
|
||||
}
|
||||
|
||||
func (template *Template) CreateContainer(processing *processing.ProcessingResource, dag *Dag) {
|
||||
container := Container{Image: processing.Container.Image}
|
||||
if container.Image == "" {
|
||||
return
|
||||
}
|
||||
container.Command = []string{"sh", "-c"} // all is bash
|
||||
for name := range processing.Container.Env {
|
||||
template.Inputs.Parameters = append(template.Inputs.Parameters, Parameter{Name: name})
|
||||
}
|
||||
for _, a := range strings.Split(processing.Container.Args, " ") {
|
||||
container.Args = append(container.Args, template.replacePerEnv(a, processing.Container.Env, dag))
|
||||
}
|
||||
cmd := strings.ReplaceAll(processing.Container.Command, container.Image, "")
|
||||
container.Args = []string{cmd + " " + strings.Join(container.Args, " ")}
|
||||
template.Container = container
|
||||
}
|
||||
|
||||
func (template *Template) replacePerEnv(arg string, envs map[string]string, dag *Dag) string {
|
||||
for k, v := range envs {
|
||||
if strings.Contains(arg, k) {
|
||||
value := v
|
||||
for _, task := range dag.Tasks {
|
||||
if task.Name == template.Name {
|
||||
for _, p := range task.Arguments.Parameters {
|
||||
if p.Name == k {
|
||||
value = p.Value
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
arg = strings.ReplaceAll(arg, "$"+k, value)
|
||||
arg = strings.ReplaceAll(arg, "${"+k+"}", value)
|
||||
arg = strings.ReplaceAll(arg, k, value)
|
||||
}
|
||||
}
|
||||
return arg
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user