Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Le Zhang <[email protected]>
  • Loading branch information
LiilyZhang committed Aug 22, 2024
1 parent 4e4c0a0 commit 7898d3f
Showing 1 changed file with 26 additions and 71 deletions.
97 changes: 26 additions & 71 deletions agreementbot/agreementworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,89 +529,44 @@ func (b *BaseAgreementWorker) InitiateNewAgreement(cph ConsumerProtocolHandler,

// The arch field in the workload could be empty or a '*' meaning any arch. If that's the case, we will use the device's arch
// when we search for services.
synonymArch := ""
workloadArch := ""

glog.V(2).Infof(BAWlogstring(workerId, fmt.Sprintf("lily - 1. workload.Arch: %v, device arch: %v", workload.Arch, exchangeDev.Arch)))
if workload.Arch == "" || workload.Arch == "*" {
//workload.Arch = exchangeDev.Arch
// Need to find if there is a service exists which arch matches the device arch
servicesMap, err := exchange.GetHTTPSelectedServicesHandler(cph)(workload.WorkloadURL, workload.Org, workload.Version, workloadArch)
findService := false
if err != nil {
glog.Errorf(BAWlogstring(workerId, fmt.Sprintf("error searching for service details with workload arch set to empty, error: %v", err)))
return
} else if len(servicesMap) == 0 {
glog.Errorf(BAWlogstring(workerId, fmt.Sprintln("0 service details with empty workload arch is returned")))
return
} else {
glog.V(5).Infof(BAWlogstring(workerId, fmt.Sprintf("services returned with empty workload arch are: %v", servicesMap)))

// glog.V(2).Info(BAWlogstring(workerId, fmt.Sprintf("lily - 2. workload.Arch: %v, device arch: %v, workload arch synonym: %v", workload.Arch, exchangeDev.Arch, b.config.ArchSynonyms.GetCanonicalArch(workload.Arch))))
// // here the workload arch could be convert to either device arch (amd64) or the sysnonym (x86_64)
// if workload.Arch != "" && b.config.ArchSynonyms.GetCanonicalArch(workload.Arch) != "" {
// synonymArch = b.config.ArchSynonyms.GetCanonicalArch(workload.Arch)
// }

glog.V(2).Infof(BAWlogstring(workerId, fmt.Sprintf("lily - 2. workload.Arch: %v, synonymArch: %v", workload.Arch, synonymArch)))
} else {
workloadArch = workload.Arch
}

glog.V(2).Infof(BAWlogstring(workerId, fmt.Sprintf("lily - will try both device arch: %v and %v", workload.Arch, synonymArch)))
_, _, _, err := exchange.GetHTTPServiceResolverHandler(cph)(workload.WorkloadURL, workload.Org, workload.Version, workloadArch)
if err != nil {
// glog.V(2).Info(BAWlogstring(workerId, fmt.Sprintf("lily - try searching service %v with arch synonym %v,", workload, synonymArch)))
// workload.Arch = synonymArch
// asl, workloadDetails, sIds, err = exchange.GetHTTPServiceResolverHandler(cph)(workload.WorkloadURL, workload.Org, workload.Version, workload.Arch)
// if err != nil {
// glog.Errorf(BAWlogstring(workerId, fmt.Sprintf("lily - error searching for service details with arch synonym %v, error: %v", workload, err)))
// return
// }
glog.Errorf(BAWlogstring(workerId, fmt.Sprintf("lily - error searching for service details with workload arch:%v, %v, error: %v", workloadArch, workload, err)))
//return
} else {
glog.V(2).Infof(BAWlogstring(workerId, fmt.Sprintf("lily - get workload details with GetHTTPServiceResolverHandler: %v", workload.Arch)))

}

// map[string]ServiceDefinition, error

servicesMap, err := exchange.GetHTTPSelectedServicesHandler(cph)(workload.WorkloadURL, workload.Org, workload.Version, workloadArch)
//var findService *exchange.ServiceDefinition
findService := false
if err != nil {
glog.Errorf(BAWlogstring(workerId, fmt.Sprintf("lily - error searching for service details with workload arch set to empty, error: %v", err)))
return
} else if len(servicesMap) == 0 {
glog.Errorf(BAWlogstring(workerId, fmt.Sprintf("lily - 0 service details with empty workload arch is returned")))
return
} else {
glog.V(2).Infof(BAWlogstring(workerId, fmt.Sprintf("lily - services returned with empty workload arch are: %v", servicesMap)))

for _, service := range servicesMap {
if exchangeDev.Arch == service.Arch {
glog.V(2).Infof(BAWlogstring(workerId, fmt.Sprintf("lily - find service has same arch with device: %v", servicesMap)))
//findService = &service
workload.Arch = service.Arch
findService = true
} else if exchangeDev.Arch == b.config.ArchSynonyms.GetCanonicalArch(service.Arch) {
glog.V(2).Infof(BAWlogstring(workerId, fmt.Sprintf("lily - find service has synonyms arch with device: %v", servicesMap)))
workload.Arch = service.Arch
findService = true
//findService = &service
//service.Arch = b.config.ArchSynonyms.GetCanonicalArch(service.Arch)
for _, service := range servicesMap {
if exchangeDev.Arch == service.Arch || exchangeDev.Arch == b.config.ArchSynonyms.GetCanonicalArch(service.Arch) {
glog.V(3).Infof(BAWlogstring(workerId, fmt.Sprintf("find service has same arch or synonym arch with device: %v", service)))
workload.Arch = service.Arch
findService = true
}
}
if !findService {
glog.Errorf(BAWlogstring(workerId, fmt.Sprintln("failed to find service details with matched workload arch")))
return
}
}
if !findService {
glog.Errorf(BAWlogstring(workerId, fmt.Sprintf("lily - failed to find service details with matched workload arch")))
return
}
} else {
workloadArch = workload.Arch
}

glog.V(2).Infof(BAWlogstring(workerId, fmt.Sprintf("lily - try to call GetHTTPServiceResolverHandler again with workload.Arch: %v", workload.Arch)))
asl, workloadDetails, sIds, err := exchange.GetHTTPServiceResolverHandler(cph)(workload.WorkloadURL, workload.Org, workload.Version, workload.Arch)
if err != nil {
// glog.V(2).Info(BAWlogstring(workerId, fmt.Sprintf("lily - try searching service %v with arch synonym %v,", workload, synonymArch)))
// workload.Arch = synonymArch
// asl, workloadDetails, sIds, err = exchange.GetHTTPServiceResolverHandler(cph)(workload.WorkloadURL, workload.Org, workload.Version, workload.Arch)
// if err != nil {
// glog.Errorf(BAWlogstring(workerId, fmt.Sprintf("lily - error searching for service details with arch synonym %v, error: %v", workload, err)))
// return
// }
glog.Errorf(BAWlogstring(workerId, fmt.Sprintf("lily - error searching for service details with workload arch:%v, %v, error: %v", workloadArch, workload, err)))
//return
glog.Errorf(BAWlogstring(workerId, fmt.Sprintf("error searching for service details with workload arch:%v, %v, error: %v", workloadArch, workload, err)))
return
} else {
glog.V(2).Infof(BAWlogstring(workerId, fmt.Sprintf("lily - get workload details with GetHTTPServiceResolverHandler: %v", workload.Arch)))
glog.V(2).Infof(BAWlogstring(workerId, fmt.Sprintf("get workload details with GetHTTPServiceResolverHandler: %v", workload.Arch)))

}

Expand Down

0 comments on commit 7898d3f

Please sign in to comment.