fix ic duplication

This commit is contained in:
irismarie 2021-10-14 11:06:10 +02:00
parent 57f1ad90ae
commit 2932d89147
2 changed files with 45 additions and 20 deletions

View file

@ -26,6 +26,7 @@ import (
"encoding/json"
"fmt"
"log"
"strconv"
"time"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
@ -47,15 +48,42 @@ type Action struct {
Results json.RawMessage `json:"results,omitempty"`
}
type Container struct {
Name string `json:"name"`
Image string `json:"image"`
}
type TemplateSpec struct {
Containers []Container `json:"containers"`
}
type JobTemplate struct {
Spec TemplateSpec `json:"spec"`
}
type JobSpec struct {
Active int `json:"activeDeadlineSeconds"`
Template JobTemplate `json:"template"`
}
type JobMetaData struct {
JobName string `json:"name"`
}
type KubernetesJob struct {
Spec JobSpec `json:"spec"`
MetaData JobMetaData `json:"metadata"`
}
type ICPropertiesToCopy struct {
Job json.RawMessage `json:"job"`
UUID string `json:"uuid"`
Name string `json:"name"`
Description string `json:"description"`
Location string `json:"location"`
Owner string `json:"owner"`
Category string `json:"category"`
Type string `json:"type"`
Job KubernetesJob `json:"job"`
UUID string `json:"uuid"`
Name string `json:"name"`
Description string `json:"description"`
Location string `json:"location"`
Owner string `json:"owner"`
Category string `json:"category"`
Type string `json:"type"`
}
type ICUpdateToCopy struct {
@ -242,28 +270,26 @@ func CheckConnection() error {
func RequestICcreateAMQP(ic *database.InfrastructureComponent, managerUUID string) (string, error) {
newUUID := uuid.New().String()
log.Printf("New IC UUID: %s", newUUID)
var lastUpdate ICUpdateToCopy
log.Println(ic.StatusUpdateRaw.RawMessage)
err := json.Unmarshal(ic.StatusUpdateRaw.RawMessage, &lastUpdate)
if err != nil {
return newUUID, err
}
var jobdef string
err = json.Unmarshal(lastUpdate.Properties.Job, &jobdef)
if err != nil {
return newUUID, err
}
msg := `{"name": "` + lastUpdate.Properties.Name + `",` +
`"description": "` + lastUpdate.Properties.Description + `",` +
`"description": "copy of ` + ic.UUID + `",` +
`"location": "` + lastUpdate.Properties.Location + `",` +
`"category": "` + lastUpdate.Properties.Category + `",` +
`"type": "` + lastUpdate.Properties.Type + `",` +
`"uuid": "` + newUUID + `",` +
`"properties": {` +
`"job": "` + jobdef + `",` +
`}}`
`"jobname": "` + lastUpdate.Properties.Job.MetaData.JobName + `",` +
`"activeDeadlineSeconds": "` + strconv.Itoa(lastUpdate.Properties.Job.Spec.Active) + `",` +
`"containername": "` + lastUpdate.Properties.Job.Spec.Template.Spec.Containers[0].Name + `",` +
`"image": "` + lastUpdate.Properties.Job.Spec.Template.Spec.Containers[0].Image + `",` +
`"uuid": "` + newUUID + `"}`
log.Print(msg)

View file

@ -423,7 +423,7 @@ func DuplicateScenarioForUser(so *database.Scenario, user *database.User) {
duplicatedICuuids[ic.ID] = duplicateUUID
if err != nil { // TODO: should this function call be interrupted here?
log.Printf("Duplication of IC (id=%d) unsuccessful", icID)
log.Printf("Duplication of IC (id=%d) unsuccessful, err: %s", icID, err)
continue
}
externalUUIDs = append(externalUUIDs, duplicateUUID)
@ -439,7 +439,6 @@ func DuplicateScenarioForUser(so *database.Scenario, user *database.User) {
var timeout = 5 // seconds
for i := 0; i < timeout; i++ {
log.Printf("i = %d", i)
if icsToWaitFor == 0 {
appendix := fmt.Sprintf("--%s-%d-%d", user.Username, user.ID, so.ID)
duplicateScenario(so, &duplicatedScenario, duplicatedICuuids, appendix)