fix ic duplication

This commit is contained in:
irismarie 2021-10-14 11:06:10 +02:00
parent 57f1ad90ae
commit 8b32fe8def
2 changed files with 48 additions and 24 deletions

View file

@ -47,15 +47,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 string `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 {
@ -240,30 +267,27 @@ func CheckConnection() error {
return nil return nil
} }
func RequestICcreateAMQP(ic *database.InfrastructureComponent, managerUUID string) (string, error) { func RequestICcreateAMQP(ic *database.InfrastructureComponent, managerUUID string, userName 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 msg := `{"name": "` + lastUpdate.Properties.Name + ` ` + userName + `",` +
err = json.Unmarshal(lastUpdate.Properties.Job, &jobdef)
if err != nil {
return newUUID, err
}
msg := `{"name": "` + lastUpdate.Properties.Name + `",` +
`"description": "` + lastUpdate.Properties.Description + `",` +
`"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": "` + 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)

View file

@ -419,11 +419,11 @@ func DuplicateScenarioForUser(so *database.Scenario, user *database.User) {
} }
if ic.Category == "simulator" && ic.Type == "kubernetes" { if ic.Category == "simulator" && ic.Type == "kubernetes" {
duplicateUUID, err := helper.RequestICcreateAMQP(&ic, ic.Manager) duplicateUUID, err := helper.RequestICcreateAMQP(&ic, ic.Manager, user.Username)
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)
@ -436,10 +436,9 @@ func DuplicateScenarioForUser(so *database.Scenario, user *database.User) {
// copy scenario after all new external ICs are in DB // copy scenario after all new external ICs are in DB
icsToWaitFor := len(externalUUIDs) icsToWaitFor := len(externalUUIDs)
var duplicatedScenario database.Scenario var duplicatedScenario database.Scenario
var timeout = 5 // seconds var timeout = 20 // 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)
@ -473,6 +472,7 @@ func DuplicateScenarioForUser(so *database.Scenario, user *database.User) {
} }
} }
} }
log.Printf("ALERT! Timed out while waiting for IC duplication, scenario not duplicated")
}() }()
} }