mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
fix ic duplication
This commit is contained in:
parent
57f1ad90ae
commit
2932d89147
2 changed files with 45 additions and 20 deletions
|
@ -26,6 +26,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
|
@ -47,15 +48,42 @@ type Action struct {
|
||||||
Results json.RawMessage `json:"results,omitempty"`
|
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 {
|
type ICPropertiesToCopy struct {
|
||||||
Job json.RawMessage `json:"job"`
|
Job KubernetesJob `json:"job"`
|
||||||
UUID string `json:"uuid"`
|
UUID string `json:"uuid"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
Owner string `json:"owner"`
|
Owner string `json:"owner"`
|
||||||
Category string `json:"category"`
|
Category string `json:"category"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ICUpdateToCopy struct {
|
type ICUpdateToCopy struct {
|
||||||
|
@ -242,28 +270,26 @@ func CheckConnection() error {
|
||||||
|
|
||||||
func RequestICcreateAMQP(ic *database.InfrastructureComponent, managerUUID string) (string, error) {
|
func RequestICcreateAMQP(ic *database.InfrastructureComponent, managerUUID string) (string, error) {
|
||||||
newUUID := uuid.New().String()
|
newUUID := uuid.New().String()
|
||||||
|
log.Printf("New IC UUID: %s", newUUID)
|
||||||
|
|
||||||
var lastUpdate ICUpdateToCopy
|
var lastUpdate ICUpdateToCopy
|
||||||
|
log.Println(ic.StatusUpdateRaw.RawMessage)
|
||||||
err := json.Unmarshal(ic.StatusUpdateRaw.RawMessage, &lastUpdate)
|
err := json.Unmarshal(ic.StatusUpdateRaw.RawMessage, &lastUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newUUID, err
|
return newUUID, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var jobdef string
|
|
||||||
err = json.Unmarshal(lastUpdate.Properties.Job, &jobdef)
|
|
||||||
if err != nil {
|
|
||||||
return newUUID, err
|
|
||||||
}
|
|
||||||
|
|
||||||
msg := `{"name": "` + lastUpdate.Properties.Name + `",` +
|
msg := `{"name": "` + lastUpdate.Properties.Name + `",` +
|
||||||
`"description": "` + lastUpdate.Properties.Description + `",` +
|
`"description": "copy of ` + ic.UUID + `",` +
|
||||||
`"location": "` + lastUpdate.Properties.Location + `",` +
|
`"location": "` + lastUpdate.Properties.Location + `",` +
|
||||||
`"category": "` + lastUpdate.Properties.Category + `",` +
|
`"category": "` + lastUpdate.Properties.Category + `",` +
|
||||||
`"type": "` + lastUpdate.Properties.Type + `",` +
|
`"type": "` + lastUpdate.Properties.Type + `",` +
|
||||||
`"uuid": "` + newUUID + `",` +
|
`"uuid": "` + newUUID + `",` +
|
||||||
`"properties": {` +
|
`"jobname": "` + lastUpdate.Properties.Job.MetaData.JobName + `",` +
|
||||||
`"job": "` + jobdef + `",` +
|
`"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)
|
log.Print(msg)
|
||||||
|
|
||||||
|
|
|
@ -423,7 +423,7 @@ func DuplicateScenarioForUser(so *database.Scenario, user *database.User) {
|
||||||
duplicatedICuuids[ic.ID] = duplicateUUID
|
duplicatedICuuids[ic.ID] = duplicateUUID
|
||||||
|
|
||||||
if err != nil { // TODO: should this function call be interrupted here?
|
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
|
continue
|
||||||
}
|
}
|
||||||
externalUUIDs = append(externalUUIDs, duplicateUUID)
|
externalUUIDs = append(externalUUIDs, duplicateUUID)
|
||||||
|
@ -439,7 +439,6 @@ func DuplicateScenarioForUser(so *database.Scenario, user *database.User) {
|
||||||
var timeout = 5 // seconds
|
var timeout = 5 // seconds
|
||||||
|
|
||||||
for i := 0; i < timeout; i++ {
|
for i := 0; i < timeout; i++ {
|
||||||
log.Printf("i = %d", i)
|
|
||||||
if icsToWaitFor == 0 {
|
if icsToWaitFor == 0 {
|
||||||
appendix := fmt.Sprintf("--%s-%d-%d", user.Username, user.ID, so.ID)
|
appendix := fmt.Sprintf("--%s-%d-%d", user.Username, user.ID, so.ID)
|
||||||
duplicateScenario(so, &duplicatedScenario, duplicatedICuuids, appendix)
|
duplicateScenario(so, &duplicatedScenario, duplicatedICuuids, appendix)
|
||||||
|
|
Loading…
Add table
Reference in a new issue