From 2932d89147eb653b4cf188092c2f60d81a164697 Mon Sep 17 00:00:00 2001 From: irismarie Date: Thu, 14 Oct 2021 11:06:10 +0200 Subject: [PATCH] fix ic duplication --- helper/amqp.go | 62 ++++++++++++++++++++-------- routes/user/authenticate_endpoint.go | 3 +- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/helper/amqp.go b/helper/amqp.go index cac4db1..2d773d3 100644 --- a/helper/amqp.go +++ b/helper/amqp.go @@ -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) diff --git a/routes/user/authenticate_endpoint.go b/routes/user/authenticate_endpoint.go index 612975e..ce6581c 100644 --- a/routes/user/authenticate_endpoint.go +++ b/routes/user/authenticate_endpoint.go @@ -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)